मुझे लगता है कि XML डेटा के आधार पर ComboBox के साथ एक UserControl है:WPF: ComboBox करने के लिए बाइंडिंग SelectedItem
<UserControl x:Class="xxxxxxxx.MyComboBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="myComboBoxControl">
<UserControl.Resources>
<DataTemplate x:Key="dataTemplateNode">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="20"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto" MinWidth="20"/>
</Grid.ColumnDefinitions>
<Border Background="{Binding [email protected]}" Grid.Column="0">
<Image Source="{Binding [email protected]}"
Width="16"
Height="16"
Margin="3" />
</Border>
<Border Background="{Binding [email protected]}" Grid.Column="1">
<TextBlock Foreground="{Binding [email protected]}"
Margin="3"
Text="{Binding [email protected]}" />
</Border>
<Border Background="{Binding [email protected]}" Grid.Column="2">
<TextBlock Foreground="{Binding [email protected]}"
Margin="3"
FontWeight="Bold"
Text="{Binding [email protected]}" />
</Border>
</Grid>
</DataTemplate>
<XmlDataProvider x:Key="xmlNodeList"
Source="/data/Combo.xml"
XPath="/Root/Node"/>
</UserControl.Resources>
<ComboBox Name="myComboBox"
ItemsSource="{Binding Source={StaticResource xmlNodeList}}"
ItemTemplate="{StaticResource dataTemplateNode}"
HorizontalContentAlignment="Stretch" /></UserControl>
MainForm.xaml में मैं एक पाठ बॉक्स है:
<Root>
<Node Background="Yellow" Foreground="Cyan" Image="1.ico" Property="aaaa" Value="28" />
<Node Background="SlateBlue" Foreground="Black" Image="2.ico" Property="bbbb" Value="2.5" />
<Node Background="Teal" Foreground="Green" Image="3.ico" Property="cccc" Value="4.0" />
<Node Background="Yellow" Foreground="Red" Image="4.ico" Property="dddd" Value="0" /></Root>
यहाँ UserControl XAML है कि मैं अपने UserControl SelectedItem से जुड़ना चाहता हूं।
<StackPanel Orientation="Horizontal">
<local:MyComboBox1 x:Name="comboBoxST" />
<TextBox x:Name="textBoxST"/></StackPanel>
मुझे खुशी होगी कि अगर आप मुझे यह कैसे करेंगे, तो मुझे खुशी होगी।
अग्रिम धन्यवाद!
हैलो saldoukhov! प्रतिक्रिया के लिए धन्यवाद, लेकिन, दुर्भाग्यवश, आपका समाधान काम नहीं करता है :-(शायद हो सकता है कि मूल कॉम्बोबॉक्स के एक्सएमएल बाध्यकारी के कारण उपयोगकर्ता नियंत्रण में शामिल हो? – user83493
सिल्वरलाइट 5 में मेरे लिए 'XPath' निर्दिष्ट किए बिना मेरे लिए काम किया, लक्ष्यित वस्तु के संपत्ति नाम के लिए बाध्यकारी द्वारा 'टेक्स्ट = {बाइंडिंग विवरण}'। – OmegaMan