数据网格上的 WPF 触发器根据绑定隐藏/显示列
我有一个像这样的数据网格:
<DataGrid AutoGenerateColumns="False" CanUserDeleteRows="True"
HorizontalScrollBarVisibility="Hidden" Margin="10,10,10,10"
VerticalScrollBarVisibility="Visible"
CanUserAddRows="False" ItemsSource="{Binding ListGestores}"
ToolTip="Selecione uma linha e pressione DELETE para remover uma unidade.">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding TB_UNIDADE.DS_NOME_UNIDADE}" CanUserResize="False" Header="Setor" IsReadOnly="True" x:Name=""/>
<DataGridTextColumn Binding="{Binding TB_UNIDADE.TB_UNIDADE2.DS_NOME_UNIDADE}" CanUserResize="False" Header="Unidade" IsReadOnly="True" x:Name=""/>
<DataGridTextColumn Binding="{Binding TB_CONTATOS.DS_NOME}" CanUserResize="False" Header="Gestor" IsReadOnly="True" />
</DataGrid.Columns>
</DataGrid>
问题是我需要验证2列绑定是否为空,如果为空,我需要隐藏它,并更改第1列的标题。
我知道我可以使用触发器来做到这一点,但具体如何??? 我一开始是:
<DataGrid.Triggers>
<DataTrigger Binding="{Binding TB_UNIDADE.TB_UNIDADE2}" Value="{x:Null}">
<Setter Property="" Value="" />
</DataTrigger>
</DataGrid.Triggers>
但我不知道该放什么二传手或什么东西!
帮助我=]
I have a data grid like this:
<DataGrid AutoGenerateColumns="False" CanUserDeleteRows="True"
HorizontalScrollBarVisibility="Hidden" Margin="10,10,10,10"
VerticalScrollBarVisibility="Visible"
CanUserAddRows="False" ItemsSource="{Binding ListGestores}"
ToolTip="Selecione uma linha e pressione DELETE para remover uma unidade.">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding TB_UNIDADE.DS_NOME_UNIDADE}" CanUserResize="False" Header="Setor" IsReadOnly="True" x:Name=""/>
<DataGridTextColumn Binding="{Binding TB_UNIDADE.TB_UNIDADE2.DS_NOME_UNIDADE}" CanUserResize="False" Header="Unidade" IsReadOnly="True" x:Name=""/>
<DataGridTextColumn Binding="{Binding TB_CONTATOS.DS_NOME}" CanUserResize="False" Header="Gestor" IsReadOnly="True" />
</DataGrid.Columns>
</DataGrid>
The problem is that i need to verify if the 2 column binding is null, and if it is null, i need to Hide it, and Change the Header of the column 1.
I know that i can do that with Triggers, but how exactly???
I started with:
<DataGrid.Triggers>
<DataTrigger Binding="{Binding TB_UNIDADE.TB_UNIDADE2}" Value="{x:Null}">
<Setter Property="" Value="" />
</DataTrigger>
</DataGrid.Triggers>
But i don't know what setter or whatever to put !
Help me =]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
示例:
对于以下 ViewModel:
您可以使用以下示例 XAML:
和转换器:
Example:
With the following ViewModel:
You can use following sample XAML:
And converter: