public void CanRemoveAStateAndAddANewStateWithTheSameName() { var stateGroups = new VisualStateGroupList(); var visualStateGroup = new VisualStateGroup { Name = CommonStatesName }; var normalState = new VisualState { Name = NormalStateName }; var invalidState = new VisualState { Name = InvalidStateName }; stateGroups.Add(visualStateGroup); visualStateGroup.States.Add(normalState); visualStateGroup.States.Add(invalidState); var name = visualStateGroup.States[0].Name; visualStateGroup.States.Remove(visualStateGroup.States[0]); visualStateGroup.States.Add(new VisualState { Name = name }); }
static VisualStateGroupList CreateTestStateGroups() { var stateGroups = new VisualStateGroupList(); var visualStateGroup = new VisualStateGroup(); var normalState = new VisualState { Name = NormalStateName }; var greenStateTrigger = new CompareStateTrigger { Property = TestEntry.Text, Value = "Test" }; var greenState = new VisualState { Name = GreenStateName }; greenState.StateTriggers.Add(greenStateTrigger); var redStateTrigger = new CompareStateTrigger { Property = TestEntry.Text, Value = string.Empty }; var redState = new VisualState { Name = RedStateName }; redState.StateTriggers.Add(redStateTrigger); visualStateGroup.States.Add(normalState); visualStateGroup.States.Add(greenState); visualStateGroup.States.Add(redState); stateGroups.Add(visualStateGroup); return(stateGroups); }
public void CanRemoveAGroupAndAddANewGroupWithTheSameName() { var stateGroups = new VisualStateGroupList(); var visualStateGroup = new VisualStateGroup { Name = CommonStatesName }; var secondVisualStateGroup = new VisualStateGroup { Name = "Whatevs" }; var normalState = new VisualState { Name = NormalStateName }; var invalidState = new VisualState { Name = InvalidStateName }; stateGroups.Add(visualStateGroup); visualStateGroup.States.Add(normalState); visualStateGroup.States.Add(invalidState); stateGroups.Add(secondVisualStateGroup); var name = stateGroups[0].Name; stateGroups.Remove(stateGroups[0]); stateGroups.Add(new VisualStateGroup { Name = name }); }
static VisualStateGroupList CreateTestStateGroups() { var stateGroups = new VisualStateGroupList(); var visualStateGroup = new VisualStateGroup { Name = CommonStatesName }; var disabledState = new VisualState { Name = DisabledStateName }; var focusedState = new VisualState { Name = FocusedStateName }; var normalState = new VisualState { Name = NormalStateName }; var onState = new VisualState { Name = OnStateName }; var offState = new VisualState { Name = OffStateName }; visualStateGroup.States.Add(disabledState); visualStateGroup.States.Add(focusedState); visualStateGroup.States.Add(normalState); visualStateGroup.States.Add(onState); visualStateGroup.States.Add(offState); stateGroups.Add(visualStateGroup); return(stateGroups); }
public void VisualElementGoesToCorrectStateWhenAvailableFromSetter() { double targetBottomMargin = 1.5; var group = new VisualStateGroup(); var list = new VisualStateGroupList(); var normalState = new VisualState { Name = NormalStateName }; normalState.Setters.Add(new Setter { Property = View.MarginBottomProperty, Value = targetBottomMargin }); var x = new Setter { Property = VisualStateManager.VisualStateGroupsProperty, Value = list }; list.Add(group); group.States.Add(normalState); var label1 = new Label(); var label2 = new Label(); x.Apply(label1); x.Apply(label2); Assert.That(label1.Margin.Bottom, Is.EqualTo(targetBottomMargin)); Assert.That(label2.Margin.Bottom, Is.EqualTo(targetBottomMargin)); }
public void FlyoutItemLabelVisualStateManager() { var groups = new VisualStateGroupList(); var commonGroup = new VisualStateGroup(); commonGroup.Name = "CommonStates"; groups.Add(commonGroup); var normalState = new VisualState(); normalState.Name = "Normal"; var selectedState = new VisualState(); selectedState.Name = "Selected"; normalState.Setters.Add(new Setter { Property = Label.BackgroundColorProperty, Value = Color.Red, TargetName = "FlyoutItemLabel" }); selectedState.Setters.Add(new Setter { Property = Label.BackgroundColorProperty, Value = Color.Green, TargetName = "FlyoutItemLabel" }); commonGroup.States.Add(normalState); commonGroup.States.Add(selectedState); var classStyle = new Style(typeof(Grid)) { Setters = { new Setter { Property = VisualStateManager.VisualStateGroupsProperty, Value = groups } }, Class = FlyoutItem.LayoutStyle, }; Shell shell = new Shell(); shell.Resources = new ResourceDictionary { classStyle }; var shellItem = CreateShellItem(); shell.Items.Add(shellItem); var grid = GetFlyoutItemDataTemplateElement <Grid>(shell, shellItem); var label = grid.LogicalChildren.OfType <Label>().First(); Assert.AreEqual(Color.Red, label.BackgroundColor); Assert.IsTrue(VisualStateManager.GoToState(grid, "Selected")); Assert.AreEqual(Color.Green, label.BackgroundColor); }
protected override void Build(StackLayout stackLayout) { base.Build(stackLayout); var isCheckedContainer = new ValueViewContainer <CheckBox>(Test.CheckBox.IsChecked, new CheckBox() { IsChecked = true, HorizontalOptions = LayoutOptions.Start }, "IsChecked", value => value.ToString()); Add(isCheckedContainer); var checkedColorContainer = new ValueViewContainer <CheckBox>(Test.CheckBox.CheckedColor, new CheckBox() { IsChecked = true, Color = Color.Orange, HorizontalOptions = LayoutOptions.Start }, "Color", value => value.ToString()); Add(checkedColorContainer); var groupList = new VisualStateGroupList(); var group = new VisualStateGroup(); var checkedVisualState = new VisualState { Name = "IsChecked" }; checkedVisualState.Setters.Add(new Setter { Property = CheckBox.ColorProperty, Value = Color.Orange }); group.States.Add(checkedVisualState); var normalVisualState = new VisualState { Name = "Normal" }; normalVisualState.Setters.Add(new Setter { Property = CheckBox.ColorProperty, Value = Color.Red }); group.States.Add(normalVisualState); groupList.Add(group); var checkBoxStateManaged = new CheckBox() { Color = Color.Red, HorizontalOptions = LayoutOptions.Start }; VisualStateManager.SetVisualStateGroups(checkBoxStateManaged, groupList); var unCheckedColorContainer = new ValueViewContainer <CheckBox>(Test.CheckBox.UncheckedColor, checkBoxStateManaged, "Color", value => value.ToString()); Add(unCheckedColorContainer); }
View GenerateDefaultCell(string textBinding, string iconBinding) { var grid = new Grid(); var groups = new VisualStateGroupList(); var commonGroup = new VisualStateGroup(); commonGroup.Name = "CommonStates"; groups.Add(commonGroup); var normalState = new VisualState(); normalState.Name = "Normal"; commonGroup.States.Add(normalState); var selectedState = new VisualState(); selectedState.Name = "Selected"; selectedState.Setters.Add(new Setter { Property = VisualElement.BackgroundColorProperty, Value = new Color(0.95) }); commonGroup.States.Add(selectedState); VisualStateManager.SetVisualStateGroups(grid, groups); grid.HeightRequest = 50; grid.ColumnDefinitions.Add(new ColumnDefinition { Width = 54 }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); var image = new Image(); image.VerticalOptions = image.HorizontalOptions = LayoutOptions.Center; image.HeightRequest = image.WidthRequest = 24; image.SetBinding(Image.SourceProperty, iconBinding); grid.Children.Add(image); var label = new Label(); label.Margin = new Thickness(20, 0, 0, 0); label.VerticalTextAlignment = TextAlignment.Center; label.SetBinding(Label.TextProperty, textBinding); grid.Children.Add(label, 1, 0); label.FontSize = 14; label.TextColor = Color.Black.MultiplyAlpha(0.87); label.FontFamily = "sans-serif-medium"; return(grid); }
internal static IList <VisualStateGroup> Clone(this IList <VisualStateGroup> groups) { var actual = new VisualStateGroupList(); foreach (var group in groups) { actual.Add(group.Clone()); } return(actual); }
View GenerateDefaultCell(string textBinding, string iconBinding) { var grid = new Grid(); var groups = new VisualStateGroupList(); var commonGroup = new VisualStateGroup(); commonGroup.Name = "CommonStates"; groups.Add(commonGroup); var normalState = new VisualState(); normalState.Name = "Normal"; commonGroup.States.Add(normalState); var selectedState = new VisualState(); selectedState.Name = "Selected"; selectedState.Setters.Add(new Setter { Property = VisualElement.BackgroundColorProperty, Value = new Color(0.95) }); commonGroup.States.Add(selectedState); VisualStateManager.SetVisualStateGroups(grid, groups); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = 50 }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); var image = new Image(); image.VerticalOptions = image.HorizontalOptions = LayoutOptions.Center; image.HeightRequest = image.WidthRequest = 22; image.SetBinding(Image.SourceProperty, iconBinding); grid.Children.Add(image); var label = new Label(); label.VerticalTextAlignment = TextAlignment.Center; label.SetBinding(Label.TextProperty, textBinding); grid.Children.Add(label, 1, 0); label.FontSize = Device.GetNamedSize(NamedSize.Small, label); label.FontAttributes = FontAttributes.Bold; return(grid); }
static VisualStateGroupList CreateTestStateGroupsWithoutNormalState() { var stateGroups = new VisualStateGroupList(); var visualStateGroup = new VisualStateGroup { Name = CommonStatesName }; var disabledState = new VisualState { Name = DisabledStateName }; visualStateGroup.States.Add(disabledState); stateGroups.Add(visualStateGroup); return(stateGroups); }
static VisualStateGroupList CreateStateGroupsWithoutNormalState() { var stateGroups = new VisualStateGroupList(); var visualStateGroup = new VisualStateGroup { Name = CommonStatesName }; var invalidState = new VisualState { Name = InvalidStateName }; visualStateGroup.States.Add(invalidState); stateGroups.Add(visualStateGroup); return(stateGroups); }
public AccordionItem GenerateAccordionItem() { var item = new AccordionItem(); item.Header = new Label() { Text = "Cheese burger" }; item.Content = new Label() { Text = "Hamburger accompanied with melted cheese. The term itself is a portmanteau of the words cheese and hamburger. The cheese is usually sliced, then added a short time before the hamburger finishes cooking to allow it to melt." }; VisualStateGroupList visualStateGroupList = new VisualStateGroupList(); VisualStateGroup commonStateGroup = new VisualStateGroup(); VisualState expanded = new VisualState { Name = "Expanded" }; expanded.Setters.Add(new Setter { Property = AccordionItem.HeaderBackgroundColorProperty, Value = Color.Red }); expanded.Setters.Add(new Setter { Property = AccordionItem.HeaderBackgroundColorProperty, Value = Color.Red }); VisualState collapsed = new VisualState { Name = "Collapsed" }; collapsed.Setters.Add(new Setter { Property = AccordionItem.HeaderBackgroundColorProperty, Value = Color.Green }); collapsed.Setters.Add(new Setter { Property = AccordionItem.HeaderBackgroundColorProperty, Value = Color.Green }); commonStateGroup.States.Add(expanded); commonStateGroup.States.Add(collapsed); visualStateGroupList.Add(commonStateGroup); VisualStateManager.SetVisualStateGroups(item, visualStateGroupList); return(item); }
public void VisualElementGoesToCorrectStateWhenSetterHasTarget() { double defaultMargin = default(double); double targetMargin = 1.5; var label1 = new Label(); var label2 = new Label(); INameScope nameScope = new NameScope(); NameScope.SetNameScope(label1, nameScope); nameScope.RegisterName("Label1", label1); NameScope.SetNameScope(label2, nameScope); nameScope.RegisterName("Label2", label2); var list = new VisualStateGroupList { new VisualStateGroup { States = { new VisualState { Name = NormalStateName, Setters = { new Setter { Property = View.MarginBottomProperty, Value = targetMargin }, new Setter { TargetName = "Label2", Property = View.MarginTopProperty, Value = targetMargin } } } } } }; VisualStateManager.SetVisualStateGroups(label1, list); Assert.That(label1.Margin.Top, Is.EqualTo(defaultMargin)); Assert.That(label1.Margin.Bottom, Is.EqualTo(targetMargin)); Assert.That(label1.Margin.Left, Is.EqualTo(defaultMargin)); Assert.That(label2.Margin.Top, Is.EqualTo(targetMargin)); Assert.That(label2.Margin.Bottom, Is.EqualTo(defaultMargin)); }
public void ValidatePerformance(int groups, int states) { IList <VisualStateGroup> vsgs = new VisualStateGroupList(); var groupList = new List <VisualStateGroup>(); for (int n = 0; n < groups; n++) { groupList.Add(new VisualStateGroup { Name = n.ToString() }); } var watch = new Stopwatch(); watch.Start(); foreach (var group in groupList) { vsgs.Add(group); } watch.Stop(); double iterations = states; var random = new Random(); for (int n = 0; n < iterations; n++) { var state = new VisualState { Name = n.ToString() }; var group = groupList[random.Next(0, groups - 1)]; watch.Start(); group.States.Add(state); watch.Stop(); } var average = watch.ElapsedMilliseconds / iterations; Debug.WriteLine($">>>>> VisualStateManagerTests ValidatePerformance: {watch.ElapsedMilliseconds}ms over {iterations} iterations; average of {average}ms"); }
//https://github.com/dotnet/maui/issues/6251 public void AppThemeBindingInVSM() { var label = new Label() { BackgroundColor = Colors.Red }; var list = new VisualStateGroupList { new VisualStateGroup { States = { new VisualState { Name = NormalStateName }, new VisualState { Name = DisabledStateName, Setters = { new Setter { Property = View.BackgroundColorProperty, Value = new AppThemeBinding{ Light = Colors.Purple, Dark = Colors.Purple, Default = Colors.Purple } }, } } } } }; VisualStateManager.SetVisualStateGroups(label, list); Assert.That(label.BackgroundColor, Is.EqualTo(Colors.Red)); VisualStateManager.GoToState(label, DisabledStateName); Assert.That(label.BackgroundColor, Is.EqualTo(Colors.Purple)); VisualStateManager.GoToState(label, NormalStateName); Assert.That(label.BackgroundColor, Is.EqualTo(Colors.Red)); }
public void VisualElementGoesToCorrectStateWhenAvailable() { var label = new Label(); double targetBottomMargin = 1.5; var group = new VisualStateGroup(); var list = new VisualStateGroupList(); var normalState = new VisualState { Name = NormalStateName }; normalState.Setters.Add(new Setter { Property = View.MarginBottomProperty, Value = targetBottomMargin }); list.Add(group); group.States.Add(normalState); VisualStateManager.SetVisualStateGroups(label, list); Assert.That(label.Margin.Bottom, Is.EqualTo(targetBottomMargin)); }
View GenerateDefaultCell(string textBinding, string iconBinding) { var grid = new Grid(); var groups = new VisualStateGroupList(); var commonGroup = new VisualStateGroup(); commonGroup.Name = "CommonStates"; groups.Add(commonGroup); var normalState = new VisualState(); normalState.Name = "Normal"; commonGroup.States.Add(normalState); var selectedState = new VisualState(); selectedState.Name = "Selected"; selectedState.Setters.Add(new Setter { Property = VisualElement.BackgroundColorProperty, Value = Application.Current.Resources["FlyoutSelectedBackgroundColor"] }); commonGroup.States.Add(selectedState); VisualStateManager.SetVisualStateGroups(grid, groups); grid.HeightRequest = 50; grid.ColumnDefinitions.Add(new ColumnDefinition { Width = 54 }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); var image = new Image(); image.VerticalOptions = image.HorizontalOptions = LayoutOptions.Center; image.HeightRequest = image.WidthRequest = 24; image.PropertyChanged += (sender, e) => { if (e.PropertyName == nameof(Image.Source) && image.Source != null) { (image.Source as FontImageSource).SetDynamicResource(FontImageSource.ColorProperty, "FlyoutTextColor"); } }; image.SetBinding(Image.SourceProperty, iconBinding); grid.Children.Add(image); var label = new Label(); label.Margin = new Thickness(20, 0, 0, 0); label.VerticalTextAlignment = TextAlignment.Center; label.SetBinding(Label.TextProperty, textBinding); grid.Children.Add(label, 1, 0); label.FontSize = 14; label.SetDynamicResource(Label.TextColorProperty, "FlyoutTextColor"); label.Triggers.Add(new DataTrigger(typeof(Label)) { Binding = new Binding { Source = grid, Path = "BackgroundColor", }, Value = Application.Current.Resources["FlyoutSelectedBackgroundColor"], Setters = { new Setter { Property = Label.TextColorProperty, Value = Application.Current.Resources["FlyoutSelectedTextColor"], } } }); return(grid); }
protected override void Build(StackLayout stackLayout) { base.Build(stackLayout); IsEnabledStateViewContainer.View.Clicked += (sender, args) => IsEnabledStateViewContainer.TitleLabel.Text += " (Tapped)"; var borderButtonContainer = new ViewContainer <RadioButton>(Test.Button.BorderColor, new RadioButton { Text = "BorderColor", BackgroundColor = Color.Transparent, BorderColor = Color.Red, BorderWidth = 1, } ); var borderRadiusContainer = new ViewContainer <RadioButton>(Test.Button.BorderRadius, new RadioButton { Text = "BorderRadius", BackgroundColor = Color.Transparent, BorderColor = Color.Red, BorderWidth = 1, } ); var borderWidthContainer = new ViewContainer <RadioButton>(Test.Button.BorderWidth, new RadioButton { Text = "BorderWidth", BackgroundColor = Color.Transparent, BorderColor = Color.Red, BorderWidth = 15, } ); var clickedContainer = new EventViewContainer <RadioButton>(Test.Button.Clicked, new RadioButton { Text = "Clicked" } ); clickedContainer.View.Clicked += (sender, args) => clickedContainer.EventFired(); var pressedContainer = new EventViewContainer <RadioButton>(Test.Button.Pressed, new RadioButton { Text = "Pressed" } ); pressedContainer.View.Pressed += (sender, args) => pressedContainer.EventFired(); var commandContainer = new ViewContainer <RadioButton>(Test.Button.Command, new RadioButton { Text = "Command", Command = new Command(() => DisplayActionSheet("Hello Command", "Cancel", "Destroy")) } ); var fontContainer = new ViewContainer <RadioButton>(Test.Button.Font, new RadioButton { Text = "Font", Font = Font.SystemFontOfSize(NamedSize.Large, FontAttributes.Bold) } ); var textContainer = new ViewContainer <RadioButton>(Test.Button.Text, new RadioButton { Text = "Text" } ); var textColorContainer = new ViewContainer <RadioButton>(Test.Button.TextColor, new RadioButton { Text = "TextColor", TextColor = Color.Pink } ); var paddingContainer = new ViewContainer <RadioButton>(Test.Button.Padding, new RadioButton { Text = "Padding", BackgroundColor = Color.Red, Padding = new Thickness(20, 30, 60, 15) } ); var isCheckedContainer = new ValueViewContainer <RadioButton>(Test.RadioButton.IsChecked, new RadioButton() { IsChecked = true, HorizontalOptions = LayoutOptions.Start }, "IsChecked", value => value.ToString()); var checkedVisualState = new VisualState { Name = "IsChecked" }; checkedVisualState.Setters.Add(new Setter { Property = RadioButton.ButtonSourceProperty, Value = "rb_checked" }); var group = new VisualStateGroup(); group.States.Add(checkedVisualState); var normalVisualState = new VisualState { Name = "Normal" }; normalVisualState.Setters.Add(new Setter { Property = RadioButton.ButtonSourceProperty, Value = "rb_unchecked" }); group.States.Add(normalVisualState); var groupList = new VisualStateGroupList(); groupList.Add(group); var rbStateManaged = new RadioButton() { HorizontalOptions = LayoutOptions.Start }; VisualStateManager.SetVisualStateGroups(rbStateManaged, groupList); var stateManagedContainer = new ValueViewContainer <RadioButton>(Test.RadioButton.ButtonSource, rbStateManaged, "IsChecked", value => value.ToString()); Add(borderButtonContainer); Add(borderRadiusContainer); Add(borderWidthContainer); Add(clickedContainer); Add(pressedContainer); Add(commandContainer); Add(fontContainer); Add(textContainer); Add(textColorContainer); Add(paddingContainer); Add(isCheckedContainer); Add(stateManagedContainer); }
DataTemplate CreateDafaultTemplate(ITNavigtaionView?nv, bool isCollapsed) { return(new DataTemplate(() => { var grid = new Grid { HeightRequest = nv.GetTvFlyoutItemHeight(), WidthRequest = nv.GetTvFlyoutItemWidth(), BackgroundColor = Graphics.Colors.Transparent }; ColumnDefinitionCollection columnDefinitions = new ColumnDefinitionCollection(); columnDefinitions.Add(new ColumnDefinition { Width = nv.GetTvFlyoutIconColumnSize() }); columnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); grid.ColumnDefinitions = columnDefinitions; var image = new Image { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, HeightRequest = nv.GetTvFlyoutIconSize(), WidthRequest = nv.GetTvFlyoutIconSize(), Margin = new Thickness(nv.GetTvFlyoutMargin(), 0, 0, 0), }; image.SetBinding(Image.SourceProperty, new Binding("FlyoutIcon")); grid.Add(image); grid.SetColumn(image, 0); var label = new Label { FontSize = nv.GetTvFlyoutItemFontSize(), VerticalTextAlignment = TextAlignment.Center, Margin = new Thickness(nv.GetTvFlyoutMargin(), 0, 0, 0), }; label.SetBinding(Label.TextProperty, new Binding("Title")); label.SetBinding(Label.TextColorProperty, new Binding("BackgroundColor", converter: new TextColorConverter(), source: grid)); if (isCollapsed) { label.Opacity = 0; label.SetBinding(Label.OpacityProperty, new Binding("Width", converter: new OpacityConverter(label.Opacity), source: label)); } grid.Add(label); grid.SetColumn(label, 1); var groups = new VisualStateGroupList(); var commonGroup = new VisualStateGroup(); commonGroup.Name = "CommonStates"; groups.Add(commonGroup); var normalState = new VisualState(); normalState.Name = "Normal"; normalState.Setters.Add(new Setter { Property = VisualElement.BackgroundColorProperty, Value = nv.GetTvFlyoutItemColor(), }); var focusedState = new VisualState(); focusedState.Name = "Focused"; focusedState.Setters.Add(new Setter { Property = VisualElement.BackgroundColorProperty, Value = nv.GetTvFlyoutItemFocusedColor() }); var selectedState = new VisualState(); selectedState.Name = "Selected"; selectedState.Setters.Add(new Setter { Property = VisualElement.BackgroundColorProperty, Value = nv.GetTvFlyoutItemColor() }); commonGroup.States.Add(normalState); commonGroup.States.Add(focusedState); commonGroup.States.Add(selectedState); VisualStateManager.SetVisualStateGroups(grid, groups); return grid; })); }
public FlyoutItemTemplateSelector(INavigationView nv) { DefaultTemplate = new DataTemplate(() => { var grid = new Grid { HeightRequest = nv.GetFlyoutItemHeight(), WidthRequest = nv.GetFlyoutItemWidth() }; ColumnDefinitionCollection columnDefinitions = new ColumnDefinitionCollection(); columnDefinitions.Add(new ColumnDefinition { Width = nv.GetFlyoutIconColumnSize() }); columnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); grid.ColumnDefinitions = columnDefinitions; var image = new Image { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, HeightRequest = nv.GetFlyoutIconSize(), WidthRequest = nv.GetFlyoutIconSize(), Margin = new Thickness(nv.GetFlyoutMargin(), 0, 0, 0), }; image.SetBinding(Image.SourceProperty, new Binding("FlyoutIcon")); grid.Children.Add(image); var label = new Label { FontSize = nv.GetFlyoutItemFontSize(), VerticalTextAlignment = TextAlignment.Center, Margin = new Thickness(nv.GetFlyoutMargin(), 0, 0, 0), }; label.SetBinding(Label.TextProperty, new Binding("Title")); label.SetBinding(Label.TextColorProperty, new Binding("BackgroundColor", converter: new TextColorConverter(), source: grid)); grid.Children.Add(label, 1, 0); var groups = new VisualStateGroupList(); var commonGroup = new VisualStateGroup(); commonGroup.Name = "CommonStates"; groups.Add(commonGroup); var normalState = new VisualState(); normalState.Name = "Normal"; normalState.Setters.Add(new Setter { Property = VisualElement.BackgroundColorProperty, Value = nv.GetTvFlyoutItemDefaultColor() }); var focusedState = new VisualState(); focusedState.Name = "Focused"; focusedState.Setters.Add(new Setter { Property = VisualElement.BackgroundColorProperty, Value = nv.GetTvFlyoutItemFocusedColor() }); var selectedState = new VisualState(); selectedState.Name = "Selected"; selectedState.Setters.Add(new Setter { Property = VisualElement.BackgroundColorProperty, Value = nv.GetTvFlyoutItemDefaultColor() }); commonGroup.States.Add(normalState); commonGroup.States.Add(focusedState); commonGroup.States.Add(selectedState); VisualStateManager.SetVisualStateGroups(grid, groups); return(grid); }); }