How to add condition in Interaction.Triggers in xaml? - xaml

Can anyone help how to add a condition before executing the Interaction.Triggers in xaml.
Am having a button in that trigger event i will do a trainsition and before begin that transition i want check for the textbox is empty or not and then i want to execute.
<button>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<TransitionBehaviours:ShowHideWithFlip ShowElementName="AlternateFaceGrid" HideElementName="FrontFaceGrid" Direction="BottomToTopCrazy" />
</i:EventTrigger>
</i:Interaction.Triggers>
</button>

Related

How to disable a mouse scroll in Avalonia CalendarDatePicker?

I need to disable the mouse scroll functionality of the CalendarDatePicker. So far, I have not found anywhere how I can do this.
<CalendarDatePicker FontWeight="SemiBold" DisplayDateStart="{Binding
Source={x:Static sys:DateTime.Now}, StringFormat=dd/MMM/yyyy}"
SelectedDate="{Binding ExpiredDate}"
IsTodayHighlighted="True" BorderThickness="0"
VerticalContentAlignment="Center" HorizontalAlignment="Center" Background="Transparent"
Watermark="Выберите дату"
IsEnabled="{Binding !Status}"
Grid.Column="1"></CalendarDatePicker>
How can i do this?
I am not aware of the CalendarDatePicker property to disable mouse scroll functionality
Just about to ask the same question! My first approach was to try handling the PointerWheelChanged event, and simply using e.Handled = true; to prevent the event from being fired. For some reason I couldn't get the event to trigger, but this might work for you.
I ended up using a button with a Calender in a flyout, which worked nicely.
<Button Content="{Binding Date, StringFormat='\{0:d\}'}">
<Button.Flyout>
<Flyout>
<Calendar SelectedDate="{Binding Date}"></Calendar>
</Flyout>
</Button.Flyout>
</Button>

UWPCommunityToolkit DropShadowPanel on Button

I'm trying to apply a shadow effect on a button on a UWP application.
I'm using the UWPCommunityToolkit tool and the control DropShadowPanel. Here an example :
http://www.uwpcommunitytoolkit.com/en/master/controls/DropShadowPanel/
So my code for apply on a button control :
<controls:DropShadowPanel BlurRadius="{Binding BlurRadius.Value, Mode=OneWay}"
ShadowOpacity="{Binding Opacity.Value, Mode=OneWay}"
OffsetX="{Binding OffsetX.Value, Mode=OneWay}"
OffsetY="{Binding OffsetY.Value, Mode=OneWay}"
VerticalAlignment="Center"
HorizontalAlignment="Center">
<Button Content="My button" />
</controls:DropShadowPanel>
But the result is :
The shadow cover all my button control.
According to the doc Button control doesn't directy inherit from FrameworkElement, that is maybe a reason.
Regards
Hum problem solved by using custom values :
<controls:DropShadowPanel BlurRadius="4.0"
ShadowOpacity="0.70"
OffsetX="5.0"
OffsetY="5.0"
Color="Black"
VerticalAlignment="Center"
HorizontalAlignment="Center">
<Button Content="My button" Background="Aqua" />
</controls:DropShadowPanel>

Getting "Cannot add instance of type EventTriggerBehavior to collection BehaviorCollection" to make clickable TextBlock

My app had a series of buttons hardcoded to be a navigation menu, but I wanted to upgrade this to something more data-driven.
<Button Content="MyPage">
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<core:NavigateToPageAction TargetPage="Namespace.MyPage"/>
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
</Button>
But when I tried to put this behavior on a different XAML element (specifically a TextBlock as part of a data template) I got the following error.
An exception of type 'Windows.UI.Xaml.Markup.XamlParseException'
occurred in NavMockUp.Windows.exe but was not handled in user code
WinRT information: Cannot add instance of type
'Microsoft.Xaml.Interactions.Core.EventTriggerBehavior' to a
collection of type 'Microsoft.Xaml.Interactivity.BehaviorCollection'
<TextBlock Text="Click for Page">
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<core:NavigateToPageAction TargetPage="Namespace.MyPage"/>
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
</TextBlock>
Make sure you understand how EventTriggerBehaviors work
The error may be somewhat unhelpful, but this is being caused by the fact that a TextBlock element does not have an event called "Click" to attach to. Jerry Nixon has a good article on behaviors
To fix this simply replace the Click event with the Tapped event, because a TextBlock does have one of those.
<TextBlock Text="Click for Page">
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Tapped">
<core:NavigateToPageAction TargetPage="Namespace.MyPage"/>
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
</TextBlock>

Bind button header to variable + fix text in xaml

I want to bind a button header to a file name, but I want to have fix text before and after the filename. Is this possible in xaml without code behind?
Something like that:
<Button Header="Save {Binding ActiveDocument.FileName} as..." Command="{Binding ActiveDocument.SaveAsCommand}" />
Well I have never tried that to be honest. But Binding object has StringFormat property.
So you can simply try this.
<Button Content="{Binding ActiveDocument.FileName, StringFormat='Save {0} as...'}" Command="{Binding ActiveDocument.SaveAsCommand}" />
another possible way is setting Buttons ContentStringFormat property
<Button Content="{Binding ActiveDocument.FileName}" ContentStringFormat="Save {0} as..." Command="{Binding ActiveDocument.SaveAsCommand}" />

DataContext and Command in XAML when used together is not working

I have a button, when i use datacontext and command, the command not work:
<Button DataContext="{Binding horaires}" Style="{StaticResource RefreshAppBarButtonStyle}" AutomationProperties.Name="{Binding HomeAppBarTitle, Converter={StaticResource StringResourceConverter}}" Command="{Binding RefreshCommand}" ></Button>
when i delete the datacontext and set the name manually it's work:
<Button Style="{StaticResource RefreshAppBarButtonStyle}" AutomationProperties.Name="Actualiser" Command="{Binding RefreshCommand}" ></Button>
what's can be the problem??
Best regards
Does horaires have a property called RefreshCommand? I'm guessing not because you said it works without the DataContext being set.
You need to either remove the DataContext binding and change the AutomationProperties.Name property binding to use the horaires prefix like this:
<Button AutomationProperties.Name="{Binding horaires.HomeAppBarTitle, Converter={StaticResource StringResourceConverter}}"
Command="{Binding RefreshCommand}" />
Or use a RelativeSource or ElementName binding to find the UI element that has your RefreshCommand in its DataContext. For example,
<Button DataContext="{Binding horaires}"
AutomationProperties.Name="{Binding HomeAppBarTitle, Converter={StaticResource StringResourceConverter}}"
Command="{Binding DataContext.RefreshCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" />
Personally, I would go with the first one because I like to avoid setting the DataContext explicitly if possible. The UI is supposed to reflect the data behind it, and setting the DataContext manually changes this hierarchy.