如何在绑定对象上切换停靠面板为 null 而不是 null,我猜 UpdateSourceTrigger 不起作用
How to switch dockpanels on binded object is null and not null, UpdateSourceTrigger not working i guess
我有一个视图模型绑定到我的 TabItem DataContext。它显示了该停靠面板中包含的所有 UIContols(可以说停靠面板的名称是 DoockpanelWithdata)。
我想做的是,当我的 Viewmodel 对象的值等于 null 时,我想显示其他 Dockpanel 说没有数据(假设是 DoockpanelWithOutData)。
我的尝试是这样的:
当 VM==null 而不是 null 时如何切换这些停靠面板?
<TabControl>
<TabItem Name="Tab1" Cursor="Hand">
<ListView Name="lZ" ItemsSource="{Binding UObj}" SelectedItem="{Binding SelectedItem ,Mode=TwoWay}" >//On selected item i bind the the tabitem below which show different dockpanels on GM=null and not null
//columns here
</ListView>
</TabItem>
<TabItem Name="TabGraph" DataContext="{Binding GM , UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Cursor="Hand">
<DockPanel Name="DoockpanelWithOutData">
<DockPanel.Style>
<Style TargetType="DockPanel">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding GM, UpdateSourceTrigger=PropertyChanged}" Value="{x:Null}">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</DockPanel.Style>
<TextBlock>There IS NO DATA</TextBlock>
</DockPanel>
<DockPanel Name="DoockpanelWithdata">
<DockPanel.Style>
<Style TargetType="DockPanel">
<Setter Property="Visibility" Value="Visible" />
<Style.Triggers>
<DataTrigger Binding="{Binding GraphVM, UpdateSourceTrigger=PropertyChanged}" Value="{x:Null}">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</DockPanel.Style>
//Some more data
</DockPanel>
</TabItem>
</TabControl>
在视图模型中(UR1R2_VM.cs)我有:
private ObservableCollection<UModel> uObj; //binded to itemsource of another TabItem
public ObservableCollection<UModel> UObj
{
get { return uObj; }
set { uObj= value; OnPropertyChanged("UObj"); }
}
private UModel selectedItem; //Binded to listView selecteditem of another tabitem
public UModel SelectedItem //HERE INSTANCE IS CREATED
{
get { return selectedItem; }
set
{
selectedItem = value;
GM = selectedItem != null ? new GM(selectedItem.Nom) : null; //HERE INSTANCE IS CREATED
OnPropertyChanged("SelectedItem");
}
}
private GM gM;
public GM GM
{
get { return gM; }
set
{
gM = value;
OnPropertyChanged("GM");
}
}
给你..
只需确保您的 GraphVM
属性 在更改时调用 RaisePropertyChanged
(即设置为空)。这对于设置触发器很重要。
<DockPanel Name="DoockpanelWithOutData">
<DockPanel.Style>
<Style TargetType="DockPanel">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding DataContext, UpdateSourceTrigger=PropertyChanged}" Value="{x:Null}">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</DockPanel.Style>
<TextBlock>There IS NO DATA</TextBlock>
</DockPanel>
<DockPanel Name="DoockpanelWithdata">
<DockPanel.Style>
<Style TargetType="DockPanel">
<Setter Property="Visibility" Value="Visible" />
<Style.Triggers>
<DataTrigger Binding="{Binding DataContext, UpdateSourceTrigger=PropertyChanged}" Value="{x:Null}">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</DockPanel.Style>
//Some more data
</DockPanel>
我有一个视图模型绑定到我的 TabItem DataContext。它显示了该停靠面板中包含的所有 UIContols(可以说停靠面板的名称是 DoockpanelWithdata)。 我想做的是,当我的 Viewmodel 对象的值等于 null 时,我想显示其他 Dockpanel 说没有数据(假设是 DoockpanelWithOutData)。
我的尝试是这样的:
当 VM==null 而不是 null 时如何切换这些停靠面板?
<TabControl>
<TabItem Name="Tab1" Cursor="Hand">
<ListView Name="lZ" ItemsSource="{Binding UObj}" SelectedItem="{Binding SelectedItem ,Mode=TwoWay}" >//On selected item i bind the the tabitem below which show different dockpanels on GM=null and not null
//columns here
</ListView>
</TabItem>
<TabItem Name="TabGraph" DataContext="{Binding GM , UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Cursor="Hand">
<DockPanel Name="DoockpanelWithOutData">
<DockPanel.Style>
<Style TargetType="DockPanel">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding GM, UpdateSourceTrigger=PropertyChanged}" Value="{x:Null}">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</DockPanel.Style>
<TextBlock>There IS NO DATA</TextBlock>
</DockPanel>
<DockPanel Name="DoockpanelWithdata">
<DockPanel.Style>
<Style TargetType="DockPanel">
<Setter Property="Visibility" Value="Visible" />
<Style.Triggers>
<DataTrigger Binding="{Binding GraphVM, UpdateSourceTrigger=PropertyChanged}" Value="{x:Null}">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</DockPanel.Style>
//Some more data
</DockPanel>
</TabItem>
</TabControl>
在视图模型中(UR1R2_VM.cs)我有:
private ObservableCollection<UModel> uObj; //binded to itemsource of another TabItem
public ObservableCollection<UModel> UObj
{
get { return uObj; }
set { uObj= value; OnPropertyChanged("UObj"); }
}
private UModel selectedItem; //Binded to listView selecteditem of another tabitem
public UModel SelectedItem //HERE INSTANCE IS CREATED
{
get { return selectedItem; }
set
{
selectedItem = value;
GM = selectedItem != null ? new GM(selectedItem.Nom) : null; //HERE INSTANCE IS CREATED
OnPropertyChanged("SelectedItem");
}
}
private GM gM;
public GM GM
{
get { return gM; }
set
{
gM = value;
OnPropertyChanged("GM");
}
}
给你..
只需确保您的 GraphVM
属性 在更改时调用 RaisePropertyChanged
(即设置为空)。这对于设置触发器很重要。
<DockPanel Name="DoockpanelWithOutData">
<DockPanel.Style>
<Style TargetType="DockPanel">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding DataContext, UpdateSourceTrigger=PropertyChanged}" Value="{x:Null}">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</DockPanel.Style>
<TextBlock>There IS NO DATA</TextBlock>
</DockPanel>
<DockPanel Name="DoockpanelWithdata">
<DockPanel.Style>
<Style TargetType="DockPanel">
<Setter Property="Visibility" Value="Visible" />
<Style.Triggers>
<DataTrigger Binding="{Binding DataContext, UpdateSourceTrigger=PropertyChanged}" Value="{x:Null}">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</DockPanel.Style>
//Some more data
</DockPanel>