I would like to highlight a label related textbox get focus. This works:
& lt; Label Grid.Row = "1" Grid.Column = "0" Target = "{Binding ElementName = CountryCode}" & gt; & Lt; Label.Style & gt; & Lt; Style TargetType = "{x: type label}" & gt; & Lt; Style.Triggers & gt; & Lt; DataTrigger binding = "{binding element name = countrycode, path = (isFocused)}" value = "true" & gt; & Lt; Setter Property = "Foreground" Value = "Blue" /> & Lt; / DataTrigger & gt; & Lt; /Style.Triggers> & Lt; / Style & gt; & Lt; /Label.Style> & Lt; AccessText text = "{binding path = country code label}" /> & Lt; / Labels & gt; & Lt; Text box Grid.Row = "1" Grid.Column = "1" name = "country code" text = "{binding path = CountryCode}" /> But I have a bunch of these text boxes, so I like to templates the style. This works:
& lt; Style x: key = "highlightsonfox" target type = "{x: type label}" & gt; & Lt; Style.Triggers & gt; & Lt; DataTrigger binding = "{binding element name = countrycode, path = (isFocused)}" value = "true" & gt; & Lt; Setter Property = "Foreground" Value = "Blue" /> & Lt; / DataTrigger & gt; & Lt; /Style.Triggers> & Lt; / Style & gt; ... & lt; Label grid Rau = "1" grid. Column = "0" style = "{static resource highlights focus}" & gt; & Lt; AccessText text = "{binding path = country code label}" /> & Lt; / Labels & gt; & Lt; Text box grid Rau = "1" grid. Column = "1" name = "country code" text = "{binding path = country code}" /> But of course I was ElementName can not hard code so I tried to do it:
Style x: key = "Hailaitonfoks" Target type = "{x: type label}" & gt; & Lt; Style.Triggers & gt; & Lt; Data Trigger Binding = "{Binding Path = (IsFocused)}" Value = "True" & gt; & Lt; Setter Property = "Foreground" Value = "Blue" /> & Lt; / DataTrigger & gt; & Lt; /Style.Triggers> & Lt; / Style & gt; ... and & lt; Labels Grid.Row = "1" Grid.Column = "0" style = "{StaticResource HighlightOnFocus}" DataContext = "{Binding ElementName = CountryCode}" & gt; & Lt; AccessText text = "{binding path = country code label}" /> & Lt; / Labels & gt; & Lt; Text box grid Rau = "1" grid. Column = "1" name = "country code" text = "{binding path = country code}" /> But setting up DataContext in the label gets binding in my AccessText element. So the question is - is there a way to specify the element name for the style datestring in any way other than setting up datatontex? Is there a better way to accomplish what I am trying to do?
is a good solution Even:
In general, it is fairly easy thus create a custom attached property:
public static class CustomAttached {public static DependencyProperty read only IsTargetFocusedProperty = DependencyProperty.RegisterAttached ( "IsTargetFocused", typeof (bool), typeof (CustomAttached) , New FrameworkPropertyMetadata (incorrect, FrameworkproductMatDataAppsAffferRender)); Public static zero SetIsTargetFocused (UIElement element, Bool value) {element.SetValue (IsTargetFocusedProperty, Value); } Public static bool GetIsTargetFocused (UIElement element) {return (bool) element.GetValue (IsTargetFocusedProperty); }} Then add a style for highlighting:
& lt; window. Resources & gt; & Lt; Style x: key = "highlightsonfox" target type = "{x: type label}" & gt; & Lt; Style.Triggers & gt; & Lt; Trigger Property = "Local: Custom Attached. Iatactfokjed" value = "True" & gt; & Lt; Setter Property = "Background" Value = "CadetBu" /> & Lt; / Catalyst & gt; & Lt; /Style.Triggers> & Lt; / Style & gt; & Lt; /Window.Resources> And then just use it like this:
& lt; Label content = "label" style = "{StaticResource HighlightOnFocus}" Local: CustomAttached.IsTargetFocused = "{Binding Focus, Element Name = Text Box}" & gt; & Lt; / Labels & gt; & Lt; Text box x: name = "text box" text = "text box" />
Comments
Post a Comment