Search Results

Search found 9 results on 1 pages for 'datatriggers'.

Page 1/1 | 1 

  • Change Rectangle Fill Based on ColumnWidth of a grid

    - by Coesy
    Essentially i want to do as the title says, if the columnwidth is .50 then the rectangle should be red, if it's .75 then it should be amber, and if it's 1 then it should be green. I thought I could achieve this with DataTriggers but for some reason I am getting "Object Reference Not Set To An Instance Of An Object" error, here is my code, am I missing something here? FYI the width property will be changed in the backend through a timer_tick event. <Grid x:Name="Grid1" Width="300" Height="30"> <Grid.ColumnDefinitions> <ColumnDefinition x:Name="MyColumn1" Width=".50*"></ColumnDefinition> <ColumnDefinition x:Name="MyColumn2" Width=".50*"></ColumnDefinition> </Grid.ColumnDefinitions> <Grid.Triggers> <DataTrigger Binding="{Binding ElementName=MyColumn1,Path=Width}" Value=".50*"> <Setter TargetName="rect" Property="Fill" Value="Red"></Setter> </DataTrigger> <DataTrigger Binding="{Binding ElementName=MyColumn1,Path=Width}" Value=".75*"> <Setter TargetName="rect" Property="Fill" Value="Yellow"></Setter> </DataTrigger> <DataTrigger Binding="{Binding ElementName=MyColumn1,Path=Width}" Value="1"> <Setter TargetName="rect" Property="Fill" Value="Green"></Setter> </DataTrigger> </Grid.Triggers> <Rectangle x:Name="rect" Grid.Column="0" HorizontalAlignment="Stretch"></Rectangle> <Rectangle Grid.Column="1" Fill="Blue"></Rectangle> </Grid>

    Read the article

  • How can I control the height of a ListView in WPF, using a complex DataTemplate with DataTriggers?

    - by Rob Perkins
    I have a ListView element with a DataTemplate for each ListViewItem defined as follows. When run, the ListView's height is not collapsed onto the items in the view, which is undesirable behavior: <DataTemplate x:Key="LicenseItemTemplate"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <TextBlock Grid.Row="0" Text="{Binding company}"></TextBlock> <Grid Grid.Row="1" Style="{StaticResource HiddenWhenNotSelectedStyle}"> <Grid.RowDefinitions> <RowDefinition /> </Grid.RowDefinitions> <Button Grid.Row="0">ClickIt</Button> </Grid> </Grid> </DataTemplate> The second row of the outer grid has a style applied which looks like this. The purpose of the style is to : <Style TargetType="{x:Type Grid}" x:Key="HiddenWhenNotSelectedStyle" > <Style.Triggers> <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={ RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem} } }" Value="False"> <Setter Property="Grid.Visibility" Value="Collapsed" /> </DataTrigger> <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={ RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem} } }" Value="True"> <Setter Property="Grid.Visibility" Value="Visible" /> </DataTrigger> </Style.Triggers> </Style> The ListView renders like this: The desired appearance is this, when none of the elements are selected: ...with, of course, the ListView's height adjusting to accommodate the additional content when the second grid is made visible by selection. What can I do to get the desired behavior?

    Read the article

  • WPF MVVM Property Change Animation

    - by cjibo
    I am looking for a clean way to start an animation that will have dynamic values. Basically I want to do an animation where an element changes width based on the data of another element. Say I have a TextBlock that's Text Property is Binding. When this property changes I want a visual element say a Rectangle for our sake to do a DoubleAnimation changing the width from previous value to the new value. I am trying to stay away from putting code in my view if possible. I've looked into DataTriggers but they seem to require that you know what the value would be such as an Enum. In my case it is just the value changing that needs to trigger a storyboard and the animation would need to start at the current(previous) value and move nicely to the new value. Any ideas. Maybe I just missed a property.

    Read the article

  • How i can add border to ListViewItem, ListView in GridView mode.

    - by Andrew
    Hello! I want to have a border around ListViewItem (row in my case). ListView source and columns generated during Runtime. In XAML i have this structure: <ListView Name="listViewRaw"> <ListView.View> <GridView> </GridView> </ListView.View> </ListView> During Runtime i bind listview to DataTable, adding necessary columns and bindings: var view = (listView.View as GridView); view.Columns.Clear(); for (int i = 0; i < table.Columns.Count; i++) { GridViewColumn col = new GridViewColumn(); col.Header = table.Columns[i].ColumnName; col.DisplayMemberBinding = new Binding(string.Format("[{0}]", i.ToString())); view.Columns.Add(col); } listView.CoerceValue(ListView.ItemsSourceProperty); listView.DataContext = table; listView.SetBinding(ListView.ItemsSourceProperty, new Binding()); So i want to add border around each row, and set border behavior (color etc) with DataTriggers (for example if value in 1st column = "Visible", set border color to black). Can i put border through DataTemplate in ItemTemplate? I know solution, where you manipulate with CellTemplates, but i don't really like it. I want something like this if this even possible. <DataTemplate> <Border Name="Border" BorderBrush="Transparent" BorderThickness="2"> <ListViewItemRow><!-- Put my row here, but i ll know about table structure only during runtime --></ListViewItemRow> </Border> </DataTemplate>

    Read the article

  • WPF: Selecting the Target of an Animation

    - by Phil Sandler
    I am trying to create a simple (I think) animation effect based on a property change in my ViewModel. I would like the target to be a specific textblock in the control template of a custom control, which inherits from Window. From the article examples I've seen, a DataTrigger is the easiest way to accomplish this. It appears that Window.Triggers doesn't support DataTriggers, which led me to try to apply the trigger in the style. The problem I am currently having is that I can't seem to target the TextBlock (or any other child control)--what happens is which the code below is that the animation is applied to the background of the whole window. If I leave off StoryBoard.Target completely, the effect is exactly the same. Is this the right approach with the wrong syntax, or is there an easier way to accomplish this? <Style x:Key="MyWindowStyle" TargetType="{x:Type Window}"> <Setter Property="Template" Value="{StaticResource MyWindowTemplate}"/> <Style.Triggers> <DataTrigger Binding="{Binding ChangeOccurred}" Value="True"> <DataTrigger.EnterActions> <BeginStoryboard> <Storyboard BeginTime="00:00:00" Duration="0:0:2" Storyboard.Target="{Binding RelativeSource={RelativeSource AncestorType=TextBlock}}" Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)"> <ColorAnimation FillBehavior="Stop" From="Black" To="Red" Duration="0:0:0.5" AutoReverse="True"/> </Storyboard> </BeginStoryboard> </DataTrigger.EnterActions> </DataTrigger> </Style.Triggers> </Style>

    Read the article

  • WPF MVVM Trigger Animation on MainWindow close

    - by Scott
    I'm using trying to implement MVVM in my app. I have a MainWindow.xaml and a MainWindowViewModel. I'm in the process of removing all of the code-behind code from the MainWindow.xaml but I'm stuck on one final piece. In my pre-MVVM setup I started an animation in the MainWindow.xaml.cs that would fade out the form before closing it. Since Closing is not a RoutedEvent, I had to use code-behind to get this to work. My VM has the following two properties that can be bound: ClosingWindow and CloseWindow. My goal was to bind a DataTrigger in my MainWindowStyle to the ClosingWindow property of the VM. When ClosingWindow was set to True, it would start an animation using the following XAML: <DataTrigger Binding="{Binding ClosingWindow}" Value="True"> <DataTrigger.EnterActions> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetProperty="Opacity" From="1" To="0" Duration="0:0:2"/> </Storyboard> </BeginStoryboard> </DataTrigger.EnterActions> </DataTrigger> Somehow (insert magic here) I was going to set CloseWindow on the VM, via Binding, to True when the animation completed, which would then use an AttachedBehavior to Close the Window. The AttachedBehavior works perfectly when I just set CloseWindow directly using the following XAML: <DataTrigger Binding="{Binding CloseWindow}" Value="True"> <Setter Property="ab:WindowCloseBehavior.Close" Value="True"/> </DataTrigger> ...but I want to reproduce the form fade before the form actually closes. So there are two issues that I've run into: First, the animation doesn't work. I enter the trigger correctly (I've taken out the animation and put a Setter statement in there that changes the Title of the MainWindow to "Closing" and it changes correctly when ClosingWindow = True) but the DoubleAnimation never does anything. Second, there's no way to set the value of CloseWindow once the animation is complete. I looked at Marlon Grech's animation code but that won't work on DataTriggers. I can't publish a RoutedEvent because my VM doesn't descend from UIElement, and I've been Googling all day trying to come up with a clever, MVVM-friendly way to do this with no luck. So any ideas why that animation doesn't do anything? And more importantly, how would you solve the entire problem of animating a form fade on close from the VM? I don't doubt that my entire solution to this problem might be whacked so I'm open to just about anything.

    Read the article

  • Collapsed Visibility Within a WPF ComboBoxItem

    - by user832747
    I used a Style setter to stretch out my ComboBoxItem (and button) so that it spans the entire length of the ComboBox like so: <ComboBox > <ComboBox.Resources> <Style TargetType="ComboBoxItem"> <Setter Property="HorizontalContentAlignment" Value="Stretch" /> </Style> </ComboBox.Resources> <ComboBoxItem > <DockPanel > <Button Content="My Button" /> </DockPanel> </ComboBoxItem> </ComboBox> This works fine. Now, I add an additional button within the same ComboBoxItem, but have it set to Visibility Collapsed. <ComboBox > <ComboBox.Resources> <Style TargetType="ComboBoxItem"> <Setter Property="HorizontalContentAlignment" Value="Stretch" /> </Style> </ComboBox.Resources> <ComboBoxItem > <DockPanel > <Button Content="My Button" /> <Button Content="My Collapsed Button" Visibility="Collapsed" /> </DockPanel> </ComboBoxItem> </ComboBox> Now, the new button is invisible, but I expected my original button to still stretch the entire ComboBox, like it does with the above code. However, it does not. Why is this so? Is there a solution for this? I am using DataTriggers to edit the Visibility property. NOTE: I also get the same thing if I just set HorizontalContentAlignment="Stretch" in the ComboBox. UPDATE: Ok, this actually has something to do with the DockPanel. I changed it to a StackPanel, and it works as desired. However, I suppose I'm still curious as to why my first button would not stretch the entire DockPanel if the second button is collapsed?

    Read the article

  • DataTriggered animation is triggered only in the first time

    - by Pavel
    I just wanted to create very simple example of DataTriggers and animation. Two checkboxes and Rectangle. Checking the first cb makes the rectangle fade away. (CodeBehind var is true) Checking the second cb makes the rectangle come back. (var is false) App is loading - the rectangle is showing (true) Firs cb is checked by default. I'm checking second cb - rect is dissapearing. It's OK. But when I then check the first cb rect isn't showing up. But checking the second cb still makes rect show up and fade away. here's my xaml and code behind: <StackPanel> <RadioButton IsChecked="True" Checked="RadioButton_Checked"></RadioButton> <RadioButton Checked="RadioButton_Checked_1"></RadioButton> <Rectangle Name="r1" Width="100" Height="300" Fill="Green"> <Rectangle.Style> <Style TargetType="Rectangle"> <Style.Triggers> <DataTrigger Binding="{Binding Active}" Value="True"> <DataTrigger.EnterActions> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:1" /> </Storyboard> </BeginStoryboard> </DataTrigger.EnterActions> </DataTrigger> <DataTrigger Binding="{Binding Active}" Value="False"> <DataTrigger.EnterActions> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetProperty="Opacity" From="1" To="0" Duration="0:0:1" /> </Storyboard> </BeginStoryboard> </DataTrigger.EnterActions> </DataTrigger> </Style.Triggers> </Style> </Rectangle.Style> </Rectangle> </StackPanel> public bool Active { get { return (bool) GetValue(ActiveProperty); } set { SetValue(ActiveProperty, value); } } public static readonly DependencyProperty ActiveProperty = DependencyProperty.Register("Active", typeof(bool), typeof(MainWindow), new UIPropertyMetadata(false)); private void RadioButton_Checked(object sender, RoutedEventArgs e) { Active = true; } private void RadioButton_Checked_1(object sender, RoutedEventArgs e) { Active = false; }

    Read the article

  • xaml : Retrigger opacity animation on multiple conditions

    - by Sdry
    I have a problem figuring out how datatriggers and multidatatriggers work. I am trying to display a message, and depending on the type of message keep it displayed( + having a background), or having it fade out by a double animation on the opacity property (+ having a transparent background). My xaml view has a game object as datacontext, which has a dependency property of type GameMessage, of which the constructor looks like this: public GameMessage(bool containsMessage, string message, bool canFadeAway) { ContainsMessage = containsMessage; Message = message; CanFadeAway = canFadeAway; } pretty straight forward, I want to display the message when ContainsMessage =equals true, and trigger a fade out animation if canFadeAway equals true. But also set the background based on canFadeAway. <Canvas Name="messageCanvas" Width="300" Height="100" Style="{StaticResource fadeInOut}"> <TextBlock Name="txtMessage" Text="{Binding Path=GameMessage.Message}" Canvas.Top="25" Canvas.Left="0" Foreground="{StaticResource MessageForegroundBrush}"> </TextBlock> </Canvas> Now, the Style and triggers is where I get into trouble: <Style.Triggers> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding Path=GameMessage.ContainsMessage}" Value="True"/> <Condition Binding="{Binding Path=GameMessage.CanFadeAway}" Value="False"/> </MultiDataTrigger.Conditions> <Setter Property="Background" Value="{StaticResource MessageBackgroundBrush}" /> <Setter Property="Opacity" Value="8" /> </MultiDataTrigger> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding Path=GameMessage.ContainsMessage}" Value="True"/> <Condition Binding="{Binding Path=GameMessage.CanFadeAway}" Value="True"/> </MultiDataTrigger.Conditions> <Setter Property="Background" Value="Transparent" /> <Setter Property="Opacity" Value="8" /> </MultiDataTrigger> <DataTrigger Binding="{Binding Path=GameMessage.CanFadeAway}" Value="True"> <DataTrigger.EnterActions> <BeginStoryboard > <Storyboard BeginTime="0:0:0" > <DoubleAnimation Storyboard.TargetProperty="Opacity" From="8" To="0" Duration="0:0:1" BeginTime="0:0:0" /> </Storyboard> </BeginStoryboard> </DataTrigger.EnterActions> <DataTrigger.ExitActions> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetProperty="Opacity" To="8" Duration="0:0:0.1" /> </Storyboard> </BeginStoryboard> </DataTrigger.ExitActions> </DataTrigger> </Style.Triggers> </Style> The problem is in resetting the opacity when the GameMessage Property ( of type GameMessage) is of type true,msg",true, and gets replaced by a GameMessage object of the same kind. The opcacity remains 0, and messages only get restored again when I have a message of kind true,"msg,false. After the animation, the opacity is 0, and where I would expect the second multidatatrigger to set it back to 8, and then have the animation performed by the Datatrigger, it doesnt. What would be the best way to get this working ?

    Read the article

1