datatrigger

MultiDataTrigger Binding to Collection and To a property within the collection

喜夏-厌秋 提交于 2019-12-11 13:24:10
问题 I have the following XAML: <Style.Triggers> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding Path=Errors, Converter={StaticResource ErrorsCountConverter}}"> <Condition.Value>True</Condition.Value> </Condition> <Condition Binding="{Binding Path=Errors[0].HasError}" Value="True" /> </MultiDataTrigger.Conditions> <Setter Property="Background" Value="Red" /> </MultiDataTrigger> </Style.Triggers> Errors is a ObservableCollection<BrokenRule> . The BrokenRule has a

EventTrigger sometimes fails to fire

徘徊边缘 提交于 2019-12-11 12:09:45
问题 I'm yet again a bit stumped, and was hoping someone could please help. Apologies in advance to the long code. Issue - I have a DataTrigger that starts off firing as expected, but it eventually fails and I can't work out why. In the example provided, it moves a rectangle around a Canvas. Each click of the button moves it in this sequence; N, NE, E, SE, S, SW, W, NW. Then it starts the sequence again, starting with N. Once the first sequence is completed, it won't move North. It will only ever

WPF: Can not find the Trigger target 'cc'. The target must appear before any Setters, Triggers

元气小坏坏 提交于 2019-12-11 06:37:30
问题 what is wrong about the following code? I get this error during compilation: The property 'TargetName' does not represent a valid target for the 'Setter' because an element named 'cc' was not found. Make sure that the target is declared before any Setters, Triggers or Conditions that use it. How do I have to refactor my code so I can compile it without error? I just want to switch a datatemplate with DataTrigger bound to a value in my PersonViewModel! <ContentControl x:Name="cc" Grid.Column=

How can I replace an image in a WPF grid with another control depending on the source data?

梦想与她 提交于 2019-12-11 06:33:33
问题 I have a grid laid out like so; +---------+---------+ | Image | Details | | is | pane | | here | for data| | | entry | +---------+---------+ | ListView here to | | select data item | | for top two panes | +---------+---------+ This all works well, but I would now like to change the image to another set of controls saying 'Sorry, no image available' when the selected item in the listview does not have an image I've tried wrapping the image in a DockPanel and setting a DataTemplate there (so I

Brush MVVM Binding does not give named color

喜你入骨 提交于 2019-12-11 05:47:09
问题 I have a MVVM binding for Border background where in I read Color names from a file in String format and convert them to Brush using the code: Brush b1 = new SolidColorBrush((Color)ColorConverter.ConvertFromString("Red"); myItem.Background = b1; Background is a property defined in ViewModel as: public Brush Background { get { return _background; } set { this._background = value; RaisePropertyChanged("Background"); } } And it is accessed in XAML as: <Border Background="{Binding Background}">

Data Trigger using Converter not working

拥有回忆 提交于 2019-12-11 01:31:54
问题 I am trying to update the color of textblock depending on it value. Seems simple however not working. Here's the textblock xaml. <TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding Path=GL, StringFormat={}{0:N0}}" HorizontalAlignment="Left" FontFamily="Verdana" Foreground="Tomato" FontWeight="Bold" VerticalAlignment="Center" Margin="5,2,5,0" FontSize="18" > <TextBlock.Resources> <converters:ColorConverter x:Key="CoConverter"></converters:ColorConverter> </TextBlock.Resources> <TextBlock

What's wrong with my datatrigger binding?

北城余情 提交于 2019-12-10 23:23:10
问题 I have created an attached property to extend a Button class with additional state: <Button v:ExtensionHelper.OperationMode="{Binding MyObject.OperationMode}" Command="{Binding MyObject.Select}" Style="{StaticResource operationModeControlTemplateStyle}" /> Then I want to access this value in the ControlTemplate using DataTrigger like this: <Style x:Key="operationModeControlTemplateStyle" TargetType="Button"> <Setter Property="IsHitTestVisible" Value="true" /> <Setter Property="Template">

XAML Trigger Auto-tab when MaxLength is Reached

荒凉一梦 提交于 2019-12-10 17:29:11
问题 How can I incorporate an auto-tab when the MaxLength property is reached into a XAML Trigger, DataTrigger, PropertyTrigger, Style.Trigger, etc. Below are two such options for how I have already accomplished this with a TextBox via code-behind. I'm looking to apply it in a XAML style as well. Thanks. XAML: <TextBox x:Name="MyTextBox" Text="{Binding Path=MyProperty}" Style="{StaticResource TextBoxStyle}" MaxLength="5" TextChanged="MyTextBox_TextChanged"> </TextBox> Code-Behind for WPF: private

Markup Extension in Data Trigger

本秂侑毒 提交于 2019-12-10 16:38:03
问题 To translate my WPF application I use a Markup extension which returns a Binding object. This allows me to switch the language while the application is running. I use this Markup like this: <TextBlock Text="{t:Translate 'My String'}" />" I would like to change a Buttons text through a data Trigger: <Button> <Button.Style> <Style TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <!-- Custom control template, note the TextBlock formating --> <ControlTemplate TargetType="

Binding to Self in Style with DataTrigger

ε祈祈猫儿з 提交于 2019-12-10 15:55:17
问题 I have a Style for a Button. Depending on if the Button is enabled or not, I want to change the Background. This is what it looks like: <Style x:Key="MyButtonStyle" TargetType="Button"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=IsEnabled, PresentationTraceSources.TraceLevel=High}" Value="False"> <Setter Property="Background" Value="Purple"/> </DataTrigger> <DataTrigger Binding="{Binding RelativeSource=