में मैं इस सरल अनुप्रयोग है कि एक combobox करने के लिए कुछ आइटम कहते हैं: यहाँसेट DataContext XAML
public partial class Window1 : Window
{
private ObservableCollection<string> _dropDownValues = new ObservableCollection<string>();
public ObservableCollection<string> DropDownValues
{
get { return _dropDownValues; }
set { _dropDownValues = value; }
}
private string _selectedValue;
public string SelectedValue
{
get { return _selectedValue; }
set { _selectedValue = value; }
}
public Window1()
{
InitializeComponent();
DataContext = this;
DropDownValues.Add("item1");
DropDownValues.Add("item1");
DropDownValues.Add("item1");
DropDownValues.Add("item1");
DropDownValues.Add("item1");
DropDownValues.Add("item1");
}
}
और XAML फाइल है:
<Window x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<StackPanel HorizontalAlignment="Left" Margin="10">
<ComboBox
Margin="0 0 0 5"
ItemsSource="{Binding DropDownValues}"
SelectedValue="{Binding SelectedValue}"
Width="150"/>
</StackPanel>
</Window>
किसी ने मुझे दिखा सकते हैं कि कैसे मैं सेट कर सकते हैं कन्स्ट्रक्टर में प्रारंभ करने के बजाय xaml फ़ाइल से DataContext?
धन्यवाद।