Setting an Initial VisualState in WPF
Tag : wpf , By : marocchino
Date : March 29 2020, 07:55 AM
Hope that helps Too long for a comment Binding "should" make no difference. If it works fine from code-behind it's bound to work from xaml unless there is something really weird in the Bindings. <Window ...
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
...>
...
<Button x:Name="button"
Style="{DynamicResource ButtonStyle1}">
<i:Interaction.Triggers>
<i:EventTrigger>
<ei:GoToStateAction StateName="YourState"
TargetObject="{Binding ElementName=button}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
|
Setting Visibility based on another control's visualstate
Date : March 29 2020, 07:55 AM
seems to work fine I would maintain the ListView selection in a property of the viewmodel and bind Grid.Visibility to that property. You will need an IValueConverter to convert from the selected item's datatype to System.Windows.Visibility, which is required for Grid.Visibility binding. In case the logic to determine visiblity is more complex, e.g. requires application state, you could add a property bool IsImportantItemSelected to the viewmodel and bind Grid.Visibility to this property. This approach allows you to keep the complex logic in the viewmodel. You'd need an IValueConverter again to convert from bool to System.Windows.Visibility.
|
Multiple VisualState Triggers for a single Visual State
Tag : chash , By : Ian Badcoe
Date : March 29 2020, 07:55 AM
Any of those help Ok. As there is no built in MultiTrigger, I wrote my own MultiTrigger. The multi trigger supports AND and OR conditions, which is exactly what I needed. It is now included in the NuGet Package AdaptiveTriggerLibrary.
|
UWP/WinRT: How to use VisualState Triggers to change the styling of all controls of a certain type?
Date : March 29 2020, 07:55 AM
I wish this help you As we've discussed in the comment, your AppBarSeparators are generated in the Pivot's DataTemplate, when controls are placed inside the DateTemplate, they becomes the visual structure of your data objects, but VisualState targets the controls, so can it not work here. You can use DataBinding with Converter to do this, and if the size of the window is changeable during the run-time, you may also need complete your data source class with INotifyPropertyChanged Interface. <Page.Resources>
<local:BoolVisibleConverter x:Key="cvt" />
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Pivot x:Name="docPivot" ItemsSource="{x:Bind pivotlist}" SizeChanged="docPivot_SizeChanged">
<Pivot.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0">
<AppBarButton Icon="Accept" Label="Accept" />
<AppBarSeparator Visibility="{Binding WindowWidth, Converter={StaticResource cvt}}" />
<AppBarButton Icon="Cancel" Label="Cancel" />
<AppBarButton Icon="Add" Label="Add" />
<AppBarSeparator Visibility="{Binding WindowWidth, Converter={StaticResource cvt}}" />
</StackPanel>
<StackPanel Orientation="Horizontal"
Grid.Row="1">
</StackPanel>
</Grid>
</DataTemplate>
</Pivot.ItemTemplate>
</Pivot>
</Grid>
private ObservableCollection<MyPivotItem> pivotlist = new ObservableCollection<MyPivotItem>();
public MainPage()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
pivotlist.Clear();
pivotlist.Add(new MyPivotItem { });
pivotlist.Add(new MyPivotItem { });
pivotlist.Add(new MyPivotItem { });
pivotlist.Add(new MyPivotItem { });
}
private void docPivot_SizeChanged(object sender, SizeChangedEventArgs e)
{
foreach (var item in docPivot.Items)
{
var pivotitem = item as MyPivotItem;
pivotitem.WindowWidth = Window.Current.Bounds.Width;
}
}
public class MyPivotItem : INotifyPropertyChanged
{
public MyPivotItem()
{
_windowwidth = Window.Current.Bounds.Width;
}
private double _windowwidth;
public double WindowWidth
{
get { return _windowwidth; }
set
{
if (value != _windowwidth)
{
_windowwidth = value;
OnPropertyChanged();
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
if (this.PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
public class BoolVisibleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
double? width = (double?)value;
if (width <= 700)
return Visibility.Collapsed;
return Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
|
Setting the initial value of a VisualState
Date : March 29 2020, 07:55 AM
Hope this helps I think that I have found the answer. I need to override the function OnApplyTemplate() in my custom control. I have extended the code of the CustomButton class with the following function: public override void OnApplyTemplate()
{
base.OnApplyTemplate();
if ( IsChecked )
{
VisualStateManager.GoToState(this, "Checked", true);
}
else
{
VisualStateManager.GoToState(this, "Unchecked", true);
}
}
|