2
我尝试使用转换器上绑定的TabItems的组合框结合WPF转换器结合 - 动态错序
我的转换器类如下
public class TabItemsCollection : IValueConverter
{
>public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
ItemCollection collection = value as ItemCollection;
IList<string> names = new List<string>();
foreach (TabItem ti in collection.SourceCollection)
{
names.Add(ti.Header.ToString());
}
return names;
}
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
我的XAML是如下
//组合框
<ComboBox Name="cmbModule"
ItemsSource="{Binding ElementName=mnuMain, Path=Items, Converter={StaticResource MenuItemsConverter}}" SelectedIndex="{Binding ElementName=mnuMain, Path=SelectedIndex}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
// TabControl的
<local:MenuTab Name="mnuMain"></local:MenuTab>
我绑定“mnuMain”与在代码隐藏一个自定义的TabControl的项目,像我这样做,我不能popularate与组合框,因为的TabItems转换器火灾第一,那么“mnuMain”。如果我在xaml中创建Tabitems,则组合框将填充tabitems,但我的问题是动态绑定。
谢谢你的解决方案,谢谢你的工作 – sumanth 2010-08-05 12:50:53
谢谢。在处理'TextBox'时,我使用了'txtFrequencyEditMode.GetBindingExpression(TextBox.TextProperty).UpdateSource()'来更新源文件! – Nasenbaer 2013-04-02 08:56:23