您好,错误是第一次初始化我的选项卡,绑定工作,但是当我想更改 tabHeader 的值时,绑定不起作用。
当我选择一个选项卡后,我想显示该按钮并隐藏所有未选择的选项卡的按钮,
主页.xaml
<TabControl TabStripPlacement="Top" ItemsSource="{Binding Tabs, Mode=TwoWay}" x:Name="ParentTab" SelectedItem="{Binding SelectedTab, Mode=TwoWay}">
<TabControl.ItemTemplate>
<DataTemplate>
<StackPanel Width="Auto" Orientation="Horizontal">
<TextBox Text="{Binding Guid, Mode=TwoWay}" Height="1" Width="1" Visibility="Hidden"></TextBox>
<Image Source="{Binding HeaderImg, Mode=TwoWay}" Height="20" Width="20"/>
<Label Content="{Binding HeaderSrt, Mode=TwoWay}" Height="Auto" Width="Auto"/>
<Button Visibility="{Binding IsEnable, Mode=TwoWay}" Content="X" Height="Auto" Width="Auto" Command="{Binding DataContext.Cmd_CloseTab,ElementName=ParentTab}"/>
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<ContentControl Content="{Binding Content}" />
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
在 HomeViewModel.cs 中
public sealed class TabItem{
public string HeaderImg { get; set; }
public string HeaderSrt { get; set; }
public string Guid { get; set; }
public Visibility IsEnable { get; set; }
public ViewModelBase Content { get; set; }
}
public class AccueilViewModel : ViewModelBase{
private TabItem m_SelectedTab;
private ObservableCollection<TabItem> m_Tabs;
public ICommand Cmd_CloseTab { get; set; }
public ObservableCollection<TabItem> Tabs{
get{ return m_Tabs; }
set{ m_Tabs = value; RaisePropertyChanged("Tabs"); }
}
public TabItem SelectedTab{
get{ return m_SelectedTab; }
set{
m_SelectedTab = value;
m_SelectedTab.IsEnable = Visibility.Visible;
ActivateBtnClose(); // The binding don't work
RaisePropertyChanged("SelectedTab");
RaisePropertyChanged("Tabs");
}
}
HUX布斯
慕姐4208626
相关分类