datatrigger

Setting up WPF treeview triggers to show different images on expand

▼魔方 西西 提交于 2019-12-03 07:47:47
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 (SolutionsViewModel) --(Solution Image) Solution 1 (Solution) --(Solution Image) Solution 2 (Solution) (Folder Image)

define animations and triggers as reusable resource?

青春壹個敷衍的年華 提交于 2019-12-03 07:22:41
问题 Is there a way to define an animation somewhere in xaml (eg. as a resource) once and then reuse it multiple times? I have a lot of independent brushes across differnt datatemplates that independently need to start the same kind of animation based on a datatrigger. Now since it seems that an animation has to define an Storyboard.TargetName and Storyboard.TargetProperty. This pretty much defeats the purpose of reusability. I would somehow like to declare "use this animation form the resource

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

妖精的绣舞 提交于 2019-12-03 04:41:51
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 Property="Background" Value="Yellow"/> </DataTrigger> </Style.Triggers> </Style> </Window.Resources>

How to make a text box Visibility=Hidden with a trigger

早过忘川 提交于 2019-12-02 23:32:21
I seem to be having a hard time today. All I want to do is make a TextBox hidden of visible based on a bool value databound to the Window its hosted in. What I have just won't compile and I don't understand why. Please help. <TextBlock Grid.Column="2" Text="This order will be sent to accounting for approval" Foreground="Red" VerticalAlignment="Center" FontWeight="Bold" Padding="5"> <TextBlock.Style> <Style> <Style.Triggers> <DataTrigger Binding="{Binding Path=AllowedToSubmit}" Value="True"> <Setter Property="Visibility" Value="Hidden" /> </DataTrigger> </Style.Triggers> </Style> </TextBlock

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

こ雲淡風輕ζ 提交于 2019-12-02 21:39:10
They seem the same. Is there a significant difference? I think I am missing something. 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. Another difference is that a DataTrigger can be bound to another control, a StaticResource, etc etc. <Style TargetType="TextBox"> <Style.Triggers> <DataTrigger Binding="{Binding SomeProperty, ElementName=someOtherControl" Value="Derp"> <!-- etc --> You can only examine the instance on which the style

define animations and triggers as reusable resource?

让人想犯罪 __ 提交于 2019-12-02 20:54:07
Is there a way to define an animation somewhere in xaml (eg. as a resource) once and then reuse it multiple times? I have a lot of independent brushes across differnt datatemplates that independently need to start the same kind of animation based on a datatrigger. Now since it seems that an animation has to define an Storyboard.TargetName and Storyboard.TargetProperty. This pretty much defeats the purpose of reusability. I would somehow like to declare "use this animation form the resource but apply it to another element this time". To me this seems to be a rather basic, important and

WPF XAML - DataTriggers or ValueConverters? Best practice

只愿长相守 提交于 2019-12-02 12:37:35
问题 I have a Window with a TextBlock . This TextBlock has to show the value "R" if the binded value is 0 or "M" if the binded value is 1. I have two possibilities: ValueConverter approach <TextBlock Binding="{Binding Path=Value, Converter={StaticResource valConverter}}"/> Where valConverter is an IValueConverter class that returns "M" or "R" if the value is respectively 0 or 1. [omitted class] DataTrigger approach <TextBlock> <TextBlock.Style> <Style> <Style.Triggers> <DataTrigger Binding="

Style with a DataTrigger that has different Bindings

自作多情 提交于 2019-12-02 05:43:59
问题 I have a series of TextBlocks to which I want apply a Style and DataTrigger. The only difference is that the Binding is to a different property in the view model for each one. Here is a simplified version of one of the TextBlocks with the Style and DataTrigger "built in". <TextBlock Text="Is development"> <TextBlock.Style> <Style TargetType="{x:Type TextBlock}"> <Style.Triggers> <DataTrigger Binding="{Binding IsDevelopmentIsDirty}" Value="True"> <Setter Property="FontWeight" Value="Bold" />

Items collection must be empty before using ItemsSource

半世苍凉 提交于 2019-12-02 03:56:40
If I put a DataTrigger in a simple Listbox I get this runtime exception: Items collection must be empty before using ItemsSource My listbox without datatrigger (no exception): <ListBox ItemsSource="{Binding EdgedBoards}" SelectedItem="{Binding SelEdgedBoard, Mode=TwoWay}" DisplayMemberPath="Name"> <ListBox.ItemContainerStyle> <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}"> <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> </Style> </ListBox.ItemContainerStyle> </ListBox> My ListBox with

use data trigger control the storyboard, but only trigger one time

淺唱寂寞╮ 提交于 2019-12-02 01:35:24
I use a data trigger to control some storyboards, but it only can be trigger one time. <Style x:Key="PropertyTriggerExampleButtonStyle" TargetType="{x:Type Button}"> <Setter Property="Width" Value="200" /> <Style.Triggers> <DataTrigger Binding="{Binding para}" Value="0"> <DataTrigger.EnterActions> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetProperty="Width" To="500" Duration="0:0:1" /> </Storyboard> </BeginStoryboard> </DataTrigger.EnterActions> </DataTrigger> <DataTrigger Binding="{Binding para}" Value="1"> <DataTrigger.EnterActions> <BeginStoryboard> <Storyboard>