datatrigger

Setting up WPF treeview triggers to show different images on expand

吃可爱长大的小学妹 提交于 2019-12-04 12:10:45
问题 I have a wpf tree view that displays nodes of various types with corresponding images such as folder images. Initially, the tree and its nodes with corresponding images display as expected. However when a node is expanded, the expectation is that the image for the expanded node should swap to an expanded image. I'm trying to use HierarchicalDataTemplate triggers to set this up. Should the triggers be set up differently? The tree looks something like: (Folder Image) Solutions

WPF ListViewItem lost focus event - How to get at the event?

淺唱寂寞╮ 提交于 2019-12-04 12:09:12
I have a listview that you select a row/item on. This is linked to a datatrigger that displays an image on the row. The image should only be displayed when the row is selected. This part works fine, however when you move the focus to something else, such as a textbox, or a messagebox is displayed, the listviewitem loses focus ie the highlight on the row is no longer displayed. The problem is that my image still remains. It should be hidden/collapsed when the listview loses focus... It works fine if you select a different item/row on the listview. Can anyone help on this please? <Style x:Key=

Datatrigger on contentpresenter.content not working

人走茶凉 提交于 2019-12-04 09:09:04
I am trying to switch the content of a contentpresenter based on a datatrigger.I want to display a usercontrol in the contentpresenter.content, if i have a value set or else i need to display an error message.But the binding on my datatrigger fails stating that the property is not found.I cant get the datacontext to inherit for the datatrigger checking.I can make it work by using the commented out code.But i am confused why it doesn't work the normal way. <ContentPresenter.Style> <Style TargetType="{x:Type ContentPresenter}"> <Setter Property="Content" Value="{Binding UC}"/> <Style.Triggers> <

WPF Calling method from a DataTrigger

北战南征 提交于 2019-12-04 05:21:04
Is it possible to use a wild card or call a method to work out if a DataTrigger should be applied? I currently have my DataList bound to an IEnumerable that contains file names and I want the file names to be greyed out if there files extension starts with "old" My non-working dream xaml markup looks something like this: <DataTemplate.Triggers> <DataTrigger Binding="{Binding}" Value="*.old*"> <Setter TargetName="FileName" Property="Foreground" Value="Gray"/> </DataTrigger> </DataTemplate.Triggers> The only workable solution I've been able to come up with is to insert a new view model property

Is it possible to use Triggers on Grid RowDefinitions?

会有一股神秘感。 提交于 2019-12-04 00:11:13
I have a grid whose rows need to be resized dynamically based on the view model. I'd like to do something like the following: <RowDefinition Height="2*"> <RowDefinition.Style> <Style> <Style.Triggers> <DataTrigger Binding="{Binding Path=ShowSection}" Value="True"> <Setter Property="RowDefinition.Height" Value="2*"/> </DataTrigger> <DataTrigger Binding="{Binding Path=ShowSection}" Value="False"> <Setter Property="RowDefinition.Height" Value="0"/> </DataTrigger> </Style.Triggers> </Style> </RowDefinition.Style> </RowDefinition> This compiles, throws no errors, but doesn't seem to have any effect

How to datatrigger an animation upon updated ViewModel property?

一曲冷凌霜 提交于 2019-12-03 16:43:18
I have the following DataGrid cell, which I would like to animate its background colour briefly as soon as the underlying LastTradePrice property changes its value. <DataGridTextColumn Header="Last Trade Price" Binding="{Binding LastTradePrice}"> <DataGridTextColumn.CellStyle> <Style TargetType="DataGridCell"> <Style.Triggers> // ??? <DataTrigger Binding="{Binding LastTradePrice}" Value="True"> <DataTrigger.EnterActions> <BeginStoryboard> <Storyboard> <ColorAnimation To="Aqua" Duration="0:0:0.3" Storyboard.TargetProperty="Background.(SolidColorBrush.Color)"/> </Storyboard> </BeginStoryboard> <

WPF Datatrigger Visibility + Null Value

喜你入骨 提交于 2019-12-03 16:19:24
I'm beginner in WPF. I want to set Visibility to Hidden on a Radiobutton when the databind value is equal to Null. I'm using WPF Toolkit. This is my code but it doesn't work : <dg:DataGrid x:Name="dtGrdData" HorizontalScrollBarVisibility="Hidden" SelectionMode="Extended" CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeRows="False" CanUserSortColumns="False" AutoGenerateColumns="False" RowHeaderWidth="0" RowHeight="50" > <DataTrigger Binding="{Binding P_DAY_PRICE}" Value="{x:Null}"> <Setter Property="RadioButton.Visibility" Value="Hidden"></Setter> </DataTrigger> <dg:DataGrid

How can I toggle a TextBlock's visibility in a DataTrigger?

寵の児 提交于 2019-12-03 15:00:50
问题 This code works (when ControlType="dropDown" then the background yellow ): <Window x:Class="TestCollapsed.Views.MainView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:c="clr-namespace:TestCollapsed.Commands" Title="Main Window" Height="400" Width="800"> <Window.Resources> <Style x:Key="DropDownStyle" TargetType="TextBlock"> <Style.Triggers> <DataTrigger Binding="{Binding ControlType}" Value="dropDown"> <Setter

Unable to set ContentTemplate via DataTrigger

荒凉一梦 提交于 2019-12-03 13:33:51
I want the ContentTemplate to vary according to the value in the DataTrigger . And yes, I considered using a DataTemplateSelector , but now I need a DataTrigger or better said a MultiDataTrigger . Please take a look at the following sample app, the DataTemplate doesn't change: <Window x:Class="Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:src="clr-namespace:WpfApplication1"> <StackPanel> <CheckBox IsChecked="{Binding BoolProperty, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type src

What's the difference between a Trigger and a DataTrigger?

巧了我就是萌 提交于 2019-12-03 08:58:24
问题 They seem the same. Is there a significant difference? I think I am missing something. 回答1: A regular trigger only responds to dependency properties. A data trigger can be triggered by any .NET property (by setting its Binding property). However, its setters can still target only dependency properties. 回答2: Another difference is that a DataTrigger can be bound to another control, a StaticResource, etc etc. <Style TargetType="TextBox"> <Style.Triggers> <DataTrigger Binding="{Binding