2017-09-12 35 views
3

我想從視圖模型中的模型綁定拾取器的值,在那裏獲取模型的路徑而不是值。視圖模型中的拾取器項目源綁定

<Picker x:Name="LocationPicker" 
    Title="Location" HeightRequest="40" 
    HorizontalOptions="FillAndExpand" 
    VerticalOptions="FillAndExpand" 
    SelectedItem="{Binding Location}" 
    ItemsSource="{Binding MaintainRoomTypes}"/> 

這裏是我的視圖模型代碼:

if (jobDetailsForFitter != null) 
{ 
    WindowDetails = new WindowDetailsModel 
    { 
     Windows = jobDetailsForFitter.Windows, 
     Locations = jobDetailsForFitter.Locations, 
     RoomTypes = jobDetailsForFitter.RoomTypes, 
     AddFiles = jobDetailsForFitter.AddFiles 
    }; 

    Locations = jobDetailsForFitter.Locations; 

    MaintainRoomTypes = jobDetailsForFitter.RoomTypes; 

    await FitterService.Instance.LoadJobDetailsToLocalStore(jobDetailsForFitter, SelectedJob?.Id ?? 0); 
} 

如何綁定的ItemSource拿到名單。

public List<Room> Locations { get; set; } 
public List<RoomTypeModel> RoomTypes { get; set; } 
+0

ItemSourcers被綁定到MaintainRoomTypes而不是位置 –

回答

5

您必須將ItemDisplayBinding屬性定義爲Picker

對於如:

public class Room 
{ 
public string RoomNumber { private set; get; } 
public string RoomName { private set; get; } 
} 

而且要在顯示ROOMNAME選擇器

<Picker ItemsSource="{Binding Room}" ItemDisplayBinding="{Binding RoomName}"/> 

希望這將解決您的問題。

+0

謝謝你的幫助@This是一個iam尋找。但在這裏我沒有從選擇器中選擇項目,有沒有辦法從選擇器中選擇項目以查看模型? – sahithi

+3

<選取器的ItemsSource = 「{結合間}」 ItemDisplayBinding = 「{結合ROOMNAME}」 的SelectedItem = 「{結合RoomSelected,模式=雙向}」/> 和在視圖模型定義RoomSelected這樣 公共室RoomSelected { 得到{return _RoomSelected; } set { _RoomSelected = value; OnPropertyChanged(); } } –

+1

再次感謝@ Sandesh Acharya。 – sahithi