Giter VIP home page Giter VIP logo

xamlbehaviors's Introduction

XAML Behaviors

XAML Behaviors is an easy-to-use means of adding common and reusable interactivity to your Windows UWP applications with minimal code. It is available for managed applications only. Use of XAML Behaviors is governed by the MIT License

Build Status

Platform Status
Managed Build Managed

Getting Started

Where to get it

Resources

More Info

Code Example

For an example of using Behaviors in an application, here is a snippet of XAML:

<Button xmlns:Core="using:Microsoft.Xaml.Interactions.Core" xmlns:Interactivity="using:Microsoft.Xaml.Interactivity">
    <Interactivity:Interaction.Behaviors>
        <Core:EventTriggerBehavior EventName="Click">
            <Core:ChangePropertyAction PropertyName="Background">
                <Core:ChangePropertyAction.Value>
                    <SolidColorBrush Color="Red"/>
                </Core:ChangePropertyAction.Value>
            </Core:ChangePropertyAction>
        </Core:EventTriggerBehavior>
    </Interactivity:Interaction.Behaviors>
</Button>

Using Behaviors SDK

The documentation explains how to install Visual Studio, add the XAML Behaviors NuGet package to your project, and get started using the API.

Building Behaviors from Source

What You Need

Clone the Repository

Build and Create Managed XAML Behaviors NuGet

  • Open the "BehaviorsSDKManaged.sln" solution in Visual Studio
  • Change Build Configuration to Release
  • Build [Ctrl + B]
  • Run msbuild /t:Pack src/BehaviorsSDKManaged/Microsoft.Xaml.Interactions.Design/Microsoft.Xaml.Interactions.Design.csproj
    • (Optional) Add /p:TimestampPackage=true to include the timestamp in the NuGet package version

For WinUI:

  • Run msbuild /t:Pack src\BehaviorsSDKManaged\Microsoft.Xaml.Interactivity.WinUI\Microsoft.Xaml.Interactivity.WinUI.csproj
    • (Optional) Add /p:TimestampPackage=true to include the timestamp in the NuGet package version

xamlbehaviors's People

Contributors

alexanderkozlenko avatar azchohfi avatar bhavyaus avatar branh avatar brianlagunas avatar capfei avatar danielchalmers avatar debonte avatar dianasoltani avatar drewgillies avatar dvaughan avatar jonwchu avatar jstedfast avatar karann-msft avatar linglingtong avatar localjoost avatar marycoder avatar mgoertz-msft avatar michael-hawker avatar microsoft-github-policy-service[bot] avatar mtaron avatar nigel-sampson avatar pedrolamas avatar scottisafool avatar sergio0694 avatar skendrot avatar sonnemaf avatar stootill-msft avatar veleek avatar wieslawsoltes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xamlbehaviors's Issues

The 'EventTriggerBehavior' does not support direct content. - "implicit_items" is null.

I created a custom data template for GridView Generated Items in my UWP app. It includes text block and image object. I'm planning change ImageSource according to the TexBlock.Text value..

     <Interactivity:Interaction.Behaviors>      
                        <Core:DataTriggerBehavior>
                            
                                <Core:ChangePropertyAction/>
                        </Core:DataTriggerBehavior>
                        </Interactivity:Interaction.Behaviors>

After that, I installed "Behaviors.Managed for UWP by Microsoft" from GitHub for creating some behaviors in my template. I drag&drop "ChangePropertyAction" to image control in my template. However, this error occurred in XAML designer:

ekran resmi 2016-10-31 19 03 24

The 'DataTriggerBehavior' does not support direct content. - Implicit_items is null.

I opened a topic in MSDN Forums about this issue. MSFT David FF suggests adding an extra code manually "Core:EventTriggerBehavior.Actions" like this:

                        <Interactivity:Interaction.Behaviors>
                           
                        <Core:DataTriggerBehavior>
                            <Core:DataTriggerBehavior.Actions>
                                <Core:ChangePropertyAction></Core:ChangePropertyAction>
                                    
                            </Core:DataTriggerBehavior.Actions>
                        </Core:DataTriggerBehavior>
                        </Interactivity:Interaction.Behaviors>

Unfortunately, I' m getting same error in Blend and VS while adding some extra code manually.
However, I do not get this error if I use behaviors on a control in my MainPage.xaml without using any template. Debugger shows an error if I drag&drop an behavior item to a control, but XAML editor running perfectly without any error and building finished successfully. I think that this bug caused from the Behaviors SDK. It looks needs a repair.

Thanks.

What means a d:IsOptimized="True" in the samples?

<DoubleAnimation Duration="0:0:2.2" To="0.35"
    Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)"
    Storyboard.TargetName="StoryboardRectangle" 
    d:IsOptimized="True"/>

Google and Bing not helped.

Unable to build samples project

Visual Studio upd 2

I just cloned the uwp behaviors project from github.
Did a build of the Managed version and then tried to build the samples and all I got was this:

C:\Projects\GitHub\XamlBehaviors\samples\CS\XAMLBehaviorsSample\CallMethodControl.DeviceFamily-Mobile.xaml(60,85): XamlCompiler error WMC0610: XBF generation error code 0x07da.

Any idea why? it's on line <Interactions:CallMethodAction TargetObject="{Binding}" MethodName="IncrementCount"/>

If I remove this I get another error later on:

C:\Projects\GitHub\XamlBehaviors\samples\CS\XAMLBehaviorsSample\ChangePropertyControl.DeviceFamily-Mobile.xaml(64,146): XamlCompiler error WMC0615: Type 'StaticResource' used after '{' must be a Markup Extension. Error code 0x07da.

On this line <Interactions:ChangePropertyAction TargetObject="{Binding ElementName=DataTriggerRectangle}" PropertyName="Fill" Value="{StaticResource PaleYellowBrush}"/>

Anyway... so I'm unable to build said project

TypeConverterHelper.Convert cannot convert double value in the language of which is comma (,) decimal point.

TypeConverterHelper.Convert cannot convert double value in the language of which is comma (,) decimal point. (e.g. Deutsch) Its methods is dependent on OS culture (see below). Is this behavior bug, or by design?

I also confirmed Windows Phone 8.1 version Behavior SDK.

// Value types in the "System" namespace must be special cased due to a bug in the xaml compiler
if (string.Equals(scope, "System", StringComparison.Ordinal))
{
  ...
  else if (string.Equals(destinationTypeFullName, typeof(double).FullName, StringComparison.Ordinal))
  {
    return double.Parse(value, CultureInfo.CurrentCulture); // ← HERE!
  }
}

https://github.com/Microsoft/XamlBehaviors/blob/858fc2b954635e3280f1eeb634773320ecc5cc58/src/BehaviorsSDKManaged/Microsoft.Xaml.Interactions/Core/TypeConverterHelper.cs#L51

Design Time Compatablility when Nesting actions in a Datatemplate UWP

When using attaching an Action to a uielement inside a datatemplate and viewing in xaml designer the code will throw the error Collection property '__implicit_items' is null. This would lead me to think I have to initialize behaviors/Actions collection before adding actions however, you still get the same error. The error is only thrown at design time and compiles and runs as expected.

This only occurs when the action is added to an element inside a datatemplate and it disables further designing of the template. This can be duplicated in both Visual studio and Blend.

Code:
<Interactivity:Interaction.Behaviors> <Core:EventTriggerBehavior EventName="Tapped"> <Core:NavigateToPageAction TargetPage="" /> </Core:EventTriggerBehavior> </Interactivity:Interaction.Behaviors>

Additional Information:
This does not happen until you attempt to enter design view. so you have to click edit generated items(itemtemplate) from the document outline.

The type 'EventTriggerBehavior' does not support direct content. (Suppression State Error)

Hello,
i have this error message in debug mode, in runtime works well.
I try sample in two different computer, but i got the same error message in the error window.
my base sample is :

xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"

    <Button Content="CLICK ME" Margin="0,10,0,0" VerticalAlignment="Top">
        <Interactivity:Interaction.Behaviors>
              <Core:EventTriggerBehavior EventName="Click">
                <Core:ChangePropertyAction PropertyName="Background">
                    <Core:ChangePropertyAction.Value>
                        <SolidColorBrush Color="#FFE02B2B"/>
                    </Core:ChangePropertyAction.Value>
                </Core:ChangePropertyAction>
            </Core:EventTriggerBehavior>
        </Interactivity:Interaction.Behaviors>
    </Button>

I have europe time zone and vb.net template.

do you have some recommendation for my case.

with best regards

AL

XamlBehaviors cause crash on phone

Hello,
I have hit a wall when trying to debug my app on phone. Everything worked well before, but now for some unknown reason each time I start my app on the phone it crashes with the following outpput:

Exception thrown: 'System.TypeLoadException' in Vtipnik.Client.WindowsUniversal.exe
'Vtipnik.Client.WindowsUniversal.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\SharedData\PhoneTools\AppxLayouts\c024fabb-341d-47d4-b8f2-054ac59096f8VS.Debug_ARM.marti\System.Resources.ResourceManager.dll'. Module was built without symbols.
Exception thrown: 'Windows.UI.Xaml.Markup.XamlParseException' in Vtipnik.Client.WindowsUniversal.exe
WinRT information: Cannot deserialize XBF metadata property list as 'Behaviors' was not found in type 'Microsoft.Xaml.Interactivity.Interaction'. [Line: 0 Position: 0]

The only place where Interactions are on the main page is the following:

        <interactivity:Interaction.Behaviors>
            <core:EventTriggerBehavior EventName="PointerReleased">
                <core:ChangePropertyAction PropertyName="IsPaneOpen" TargetObject="{Binding ElementName=SplitViewCore}" Value="{Binding ElementName=SplitViewCore, Path=IsPaneOpen, Converter={StaticResource BooleanNegationConverter}}" />
            </core:EventTriggerBehavior>
        </interactivity:Interaction.Behaviors>

I really have no idea what is wrong, I have tested the exact same code in a different blank app and it works so I am really confused...

Thank you for any ideas or directions

Combine DragPositionBehavior and Resize?

Hello,
I just have tested the sample and I would like to know if it is possible to combine the DragPositionBehaviors with a solution allowing to resize the shapes?
On my UWP app, I must allow users to add an basic shape on a photo, and then let them resizing and moving this shape on the photo...
Thanks in advance,

No interface for triggers

The current design doesn't have a contract for a trigger style behavior now that both triggers and behaviors have been merged into one.

This affects any framework that works with triggers in abstract (such as Caliburn.Micro) where the following is not possible.

IBehavior trigger = CreateTrigger();
IAction action = CreateAction();

trigger.Actions.Add(action);

I propose adding a new interface

public interface ITriggerBehavior : IBehavior
{
    ActionCollection Actions { get;}
}

and applying to this to the out of the box triggers.

Thoughts?

[Question] Can I set a value in a ViewModel reacting to an Event in the View?

Can I set a value in a ViewModel reacting to an Event in the View?

For instance, when a WebView control starts loading content, the ContentLoading  event is invoked.
When it has finished loading the content, the LoadCompleted event is invoked.

I would like to have a property in my ViewModel that is set to true/false when those events are raised. For example, a IsLoading property.

Then, I could show a ProgressRing when appropriate.

EventArgs as CommandParameter on InvokeCommandAction

Hi,
Is it possible to use event arguments as parameter for commands when using InvokeCommandAction?!
Actually I'm using ItemClick event with behaviors on a ListView & ItemClickEventArgs is the only way to know which item clicked.
Maybe It's good to notice for a reason I can't use SelectedItem, because It's null when you set SelectionMode="None" & also that I'm developing UWP app in C#.

Thanks

DataTriggerBehavior doesn't appear to work with Nullable types

I cannot get the following DataTriggerBehavior to work with a nullable type; e.g.
double? MyValue = null;

                        <i:Interaction.Behaviors>
                            <ic:DataTriggerBehavior Binding="{Binding MyValue}" Value="{x:Null}" >
                                <ic:ChangePropertyAction PropertyName="Foreground" Value="Red"/>
                            </ic:DataTriggerBehavior>
                        </i:Interaction.Behaviors>

The foreground never turns Red.

Forcing update to (DataTrigger)Behavior

Normally when trying to force an update with a binding I just raise the event of the INotifyPropertyChanged and the binding is forced updated, however when trying this to trigger the datatriggerbehavior like this it does not work untill I really have a different value.
For example I want to get the value when triggered and then with an action put it into textfield like a little log or invoke a command in the view despite being the same every time.

DataTriggerBehavior fires only first time

The request is that the row of my ListView blinks when the property SelectedItem of the ViewModel raises change.

This is my code, the problem is that it works only first time SelectedItem became true.

<DataTemplate x:Key="myDataTemplate">
    <Grid x:Name="myGrid">
        <Interactivity:Interaction.Behaviors>
            <Core:DataTriggerBehavior Binding="{Binding SelectedItem}" Value="True">
                <Media:ControlStoryboardAction>
                    <Media:ControlStoryboardAction.Storyboard>
                        <Storyboard>
                            <ColorAnimation
                                To="#009ABF" 
                                Storyboard.TargetName="myGrid" 
                                Storyboard.TargetProperty="(Grid.Background).(SolidColorBrush.Color)" 
                                AutoReverse="True" 
                                Duration="0:0:1"
                                RepeatBehavior="1x" />
                        </Storyboard>
                    </Media:ControlStoryboardAction.Storyboard>
                </Media:ControlStoryboardAction>
            </Core:DataTriggerBehavior>
        </Interactivity:Interaction.Behaviors>
        <!--OMISSIS-->
</Grid>

See detail here

DataTriggerBehavior doesn't evaluate initially, instead it will wait until the bound value has changed

Is this intended behavior?

Consider the following:

<interactivity:Interaction.Behaviors>
    <interactions:DataTriggerBehavior Binding="{x:Bind Vm.IsLiked, Mode=OneWay}" Value="False">
        <interactions:GoToStateAction StateName="NotLiked"/>
    </interactions:DataTriggerBehavior>
    <interactions:DataTriggerBehavior Binding="{x:Bind Vm.IsLiked, Mode=OneWay}" Value="True">
        <interactions:GoToStateAction StateName="Liked"/>
    </interactions:DataTriggerBehavior>
</interactivity:Interaction.Behaviors>

The visual state won't be set correctly until Vm.IsLiked actually changes value.

If this is intended behavior, then what is the best way for me to trigger an evaluation? Should I raise a property changed event for IsLiked in my view model at some point? I can't do it in the VM's constructor because there are no registered listeners yet.

Event Trigger interaction with CommandBar.SecondaryCommands

Haven't had a chance to look into the cause yet, but there is a bug where the EventTriggerBehavior is interacting incorrectly with the popup secondary commands menu of a CommandBar.

I've put up a quick sample of the bug, but the basics are that it appears the behavior is attached to the click event every time the menu is opened. Therefore when the button is clicked the accompanying action is invoked as many times as the menu was opened previously.

Support for Async/Await in Actions

XamlBehaviors are really powerfull and more lately noticed that some designers are going faster with productivity with the more small components made into it. But we are running into some small behaviors/actions issue when it comes to actions that require async/await.

A common scenario that we have is that the we have a lot of small actions that help the designers just plug in the feature where needed and out later instead of in code, this really sped up a lot of implementations and requirements but we are having issues when the designers need to do few actions in a row. For example assume there are 3 actions required to be executed but the second one is a IO operation with Async execute only that you either need to await or .Wait/Result and the third action relies on it. Currently you now either perform a blocking UI action while you want fluent UI or do in code behind (and dozen of places).

I would like to propose an addition of an IAwaitableAsync with the method Task Execute(object sender, object parameter);
SideNote: Maybe even introduce a base class like with Behavior, one named BehaviorAction and AwaitableBehaviorAction

There are few critical changes that would be required though, like the Interaction.ExecuteActions would have to do a blocking support or replaced by a new method named Interaction.ExecuteActionsAsync.
All Behaviors of the package would have to use that method to support Async/Await.
CallMethodAction should also ignore the check if a method returns nothing to match the perfect signature and in case it returns a Task it should await it.

Signing

Strongname signing of assemblies as well as potential Authenticode signing.

New Release?

Is there a new release on this going to be put out soon? I'm living with behaviors everyday in my day job, and #108 is the most aggravating thing in my life right now (AssociatedObject? Intellisense is having none of it!), so it would be much lovely if it could be pushed to NuGet sometime soon.

EventTriggerBehavior not working on custom implementations of system event handlers in Windows Runtime

I ran into a strange error using a custom DataGrid control for UWP. The control implemented it's own SelectionChanged event, basing it on the SelectionChangedEventHandler from System.Windows.Controls.

The text associated with this error code could not be found.

Cannot add instance of type 'Microsoft.Xaml.Interactions.Core.EventTriggerBehavior' to a collection of type 'Microsoft.Xaml.Interactivity.BehaviorCollection'. [Line: 148 Position: 102]

This happened because the EventTriggerBehavior attempted to handle the event with WindowsRuntimeMarshal.AddEventHandler.

Xaml looks something like this:

<mytkctl:DataGrid ItemsSource="{Binding Entries}" Name="WeightGrid">
    <Interactivity:Interaction.Behaviors>
        <Core:EventTriggerBehavior EventName="SelectionChanged" >
            <Core:InvokeCommandAction 
            Command="{Binding EntrySelectionChanged}" 
            CommandParameter="{Binding Path=SelectedItem, ElementName=WeightGrid}" />
        </Core:EventTriggerBehavior>
    </Interactivity:Interaction.Behaviors>
    <mytkctl:DataGrid.Columns>
        <mytkctl:DataGridTextColumn Header="Date" Binding="{Binding Date}" />
        <mytkctl:DataGridTextColumn Header="Weight" Binding="{Binding StringWeight}" />
    </mytkctl:DataGrid.Columns>
</mytkctl:DataGrid>

After figuring out the issue, I was able to resolve it fairly easily in the MyToolkit library, by downloading the source and adding a local copy of the SelectionChangedEventHandler delegate...

public delegate void SelectionChangedEventHandler(System.Object sender, SelectionChangedEventArgs e);

The question is how common is this issue? Is this something that all custom control libraries should watch out for? Or is this something that can be fixed in XamlBehaviors?

DataTriggerBehavior doesn't support enum comparison

It seems that binding DataTriggerBehavior to enum property on a viewmodel doesn't work and breaks other bindings in page/usercontrol too.

I'm trying to bind DataTriggerBehavior to an enum property on a viewmodel and compare it to a string representation of the enum value.

Support WPF

It seems there is no official up-to-date package that would provide the same functionality for WPF.

Update:
https://blogs.windows.com/buildingapps/2015/11/30/xaml-behaviors-open-source-and-on-uwp
http://www.infoq.com/news/2016/02/XAML-Behaviors

As of right now, XAML Behaviors have not been open sourced for WPF. However, we would like to continue to grow Behaviors. Cross-platform XAML Behaviors for things like WPF is definitely on the roadmap, and if there is interest from the community we would definitely like to bring new Behaviors to WPF in the future.

@jonwchu there is definitely an interest from the community.

http://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/5282131-open-source-behaviors-sdk-xaml-for-visual-studio

In all XAML Based technologies we use Behaviors all the time, on...

@unniravindranathan the UserVoice suggestion was unfortunately marked as "Completed" without providing WPF support.

EventTriggerBehavior working in Debug Configuration but not in Release Configuration

I am using "EventTriggerBehavior", basically
object IAction.Execute( object sender, object parameter ) for determining which page to navigate depending upon the where the click is coming form. In UWP Apps, when the configuration is Debug mode, everything seems to be working fine but when the configuration is Release mode, the parameter for ClickedItem is coming null.

Changing instanse of RenderTransform

In DragPositionBehavior.cs after pointer is pressed RenderTransform will be replaced by TranslateTransform. That is bad. Because if we have already changed it for example to ScaleTransform or CompositeTransform it will be replaced and we can't using old version.

CallMethodAction with cached navigation causes multiple method calls

Let the source page define an event behavior with a CallMethodAction. Now, when we navigate to another page and back to source page, there are two method calls registered against the said event. This issue only occurs when the source page has NavigationCache set to Enabled or Required. My guess is that the sdk keeps attaching more and more method calls against the event every time we navigate to source page. Is there any way to work around this?
I have more specific question here on StackOverflow.

ControlStoryboardAction in DataTemplate has inconsistent behavior in Anniversary Update

While building a UWP app I have noticed a very unusual behavior with ControlStoryboardAction running on Anniversary Update PCs.

Code sample

<ListView ItemsPanel="{StaticResource HorizontalPanel}" ItemsSource="{x:Bind Items}">
     <ListView.ItemTemplate>
         <DataTemplate>
             <Border x:Name="Container">
                 <Border.Background>
                     <SolidColorBrush Color="Transparent" />
                 </Border.Background>
                 <Border.Resources>
                     <Storyboard x:Key="BlinkingAnimation" RepeatBehavior="Forever" AutoReverse="True">
                         <ColorAnimation Duration="0:0:1" To="Red" Storyboard.TargetProperty="(Grid.Background).(SolidColorBrush.Color)" Storyboard.TargetName="Container">
                         </ColorAnimation>
                     </Storyboard>
                  </Border.Resources>
                  <StackPanel VerticalAlignment="Center">
                     <TextBlock Text="Is animating:" FontWeight="Bold" HorizontalAlignment="Center" />
                     <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding IsAnimating}" />
                   </StackPanel>
                   <interactivity:Interaction.Behaviors>
                       <core:DataTriggerBehavior 
                                Binding="{Binding IsAnimating, Mode=OneWay}" 
                                ComparisonCondition="Equal"
                                Value="true">
                                <media:ControlStoryboardAction ControlStoryboardOption="Play" Storyboard="{StaticResource BlinkingAnimation}" />
                       </core:DataTriggerBehavior>
                       <core:DataTriggerBehavior 
                                Binding="{Binding IsAnimating, Mode=OneWay}" 
                                ComparisonCondition="Equal"
                                Value="false">
                                <media:ControlStoryboardAction ControlStoryboardOption="Stop" Storyboard="{StaticResource BlinkingAnimation}" />
                        </core:DataTriggerBehavior>
                 </interactivity:Interaction.Behaviors>
             </Border>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Download sample

You can download the sample solution here:
AnimationInDataTemplateProblem.zip

Expected behavior

When I set Items[2].IsAnimating = true, the third item in the ListView should start animating its border's background.

Actual behavior

The actual behavior is in line with expectations on PCs and phones running 10586 (November update) and 15063 (Creators Update). However, on 14393 (Anniversary Update) whichever item's IsAnimating property is set, the storyboard always runs on the first item in the list. In fact, stepping through the code it seems that each ControlStoryboardAction has set the first item's Storyboard, which it then manipulates.

Interesting thing to note is that compiling the app against different SDK versions has no effect. Whether the app's target SDK is NU, AU or CU, the results are always the same.

Workaround

The only workaround I have found so far is to wrap the contents of the DataTemplate into a UserControl (this approach is also demonstrated in the sample solution), which works consistently everywhere. Still it is a very strange problem and I think it warrants investigation (also because AU is currently the most widely used version of W10).

10586behavior
14393behavior
15063behavior

Add new NavigateBackAction or change NavigateToPageAction

I have written a simple NavigateBackAction behavior, see https://gist.github.com/sonnemaf/0d1c6fbc3cfc4e2310c4 You can use it to implement a GoBack() navigation on a Frame.

I would like to include it in the project but this might not be a good idea. Instead of adding this behavior we could change the implementation of the NavigateToPageAction by adding a 'NavigationType' (enum: Page, Backward, Forward, ClearBackstack?) property to it. The name of the NavigateToPageAction might also have to change.

What should we do? Do we want many small/simple behaviors or do we create bigger/smarter ones with many options?

Fons

A Gitter Room would be great !!

I think there should be a gitter room for people looking forward to learn these things and want to know some things and discuss things !!

DataTriggerBehavior broken

Recently I update my app to use the nuget version of Behaviors (this repo). My app stop changing VisualState when property changed.

Here is the code:

<i:Interaction.Behaviors>
        <core:DataTriggerBehavior Binding="{Binding HeaderLoaded}"
                                  ComparisonCondition="Equal"
                                  Value="True">
            <core:GoToStateAction StateName="HeaderLoaded"
                                  TargetObject="{Binding ElementName=root}"
                                  UseTransitions="True" />
        </core:DataTriggerBehavior>
        <core:DataTriggerBehavior Binding="{Binding HeaderLoaded}"
                                  ComparisonCondition="NotEqual"
                                  Value="True">
            <core:GoToStateAction StateName="Default"
                                  TargetObject="{Binding ElementName=root}"
                                  UseTransitions="False" />
        </core:DataTriggerBehavior>
</i:Interaction.Behaviors>

I navigate to the page, Visual state changes to HeaderLoaded, I go back, it changes to Default. After that, it remains Default, despite that HeaderLoaded changes to true.
In short, Visual state never be changed after navigating from the Page.

AssociatedObject is sometimes null within ItemsControl ItemTemplate

I have an ItemsControl which displays two different types of items (using ContentPresenter/Caliburn.Micro). When I add the first item that causes a scrollbar to appear, I'm seeing OnDetaching get called:

>	BindableFocusBehavior.OnDetaching() Line 84	C#
 	Microsoft.Xaml.Interactivity.dll!Microsoft.Xaml.Interactivity.Behavior.Detach()	Unknown
 	Microsoft.Xaml.Interactivity.dll!Microsoft.Xaml.Interactivity.BehaviorCollection.Detach()	Unknown
 	Microsoft.Xaml.Interactivity.dll!Microsoft.Xaml.Interactivity.Interaction.FrameworkElement_Unloaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)	Unknown

Each item I add after that causes OnAttached/OnDetaching to get called on the same BindableFocusBehavior instance, which leaves AssociatedObject null.

>	BindableFocusBehavior.OnAttached() Line 90	C#
 	Microsoft.Xaml.Interactivity.dll!Microsoft.Xaml.Interactivity.Behavior.Attach(Windows.UI.Xaml.DependencyObject associatedObject)	Unknown
 	Microsoft.Xaml.Interactivity.dll!Microsoft.Xaml.Interactivity.BehaviorCollection.Attach(Windows.UI.Xaml.DependencyObject associatedObject)	Unknown
 	Microsoft.Xaml.Interactivity.dll!Microsoft.Xaml.Interactivity.Interaction.FrameworkElement_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)	Unknown

I'm not sure why the ItemsStackPanel is repeatedly loading/unloading the same UserControl, but is it possible that the events are being handled in the wrong order?

My workaround is currently just to store the AssociatedObject to a private field.

NavigateToPageAction.Execute can't find INavigate in ancestors of sender

NavigateToPageAction.Execute has a loop (see below) where it checks if the sender implements INavigate and if not works its way up the visual tree looking for the first INavigate ancestor. However, there's a typo in this loop where every time around the loop it's checking if sender (the original sender parameter) implements INavigate rather than checking senderObject (the ancestor). So if the sender parameter is not an INavigate, Execute always fails.

87 DependencyObject senderObject = sender as DependencyObject;
88
89 // If the sender wasn't an INavigate, then keep looking up the tree from the
90 // root we were given for another INavigate.
91 while (senderObject != null && navigateElement == null)
92 {
93 navigateElement = sender as INavigate;
94 if (navigateElement == null)
95 {
96 senderObject = VisualTreeHelper.GetParent(senderObject);
97 }
98 }
99
100 if (navigateElement == null)
101 {
102 return false;
103 }

Localization

Identify localization process and potentially port existing Behaviors SDK localized resources.

Language issue when submitted to store

Hi,
I'm using the latest Nuget version, 1.0.3, managed.
My projects has french resources, in a /Resources/fr/resources.resw file.
When I submit my project to the store, it wants me to add a description for the fr-FR language, which is not correct because I don't explicitly support it.
When I remove the XamlBehaviors package it doesn't ask me for an extra language, which is the expected behaviour.
I already tried this solution : http://metronuggets.com/2015/12/03/got-unexpected-extra-languages-in-your-uwp-store-submission/ but it doesn't solve anything.
Any idea about this ?

Regards,

EventTriggerBehavior throws exception with SourceObject="{x:Bind ...}"

I have noticed that when using EventTriggerBehavior with SourceObject="{x:Bind ...} you must always have an event name that is available in the parent container even if you define because otherwise it will throw an exception as followed:

Cannot add instance of type 'Microsoft.Xaml.Interactions.Core.EventTriggerBehavior' to a collection of type 'Microsoft.Xaml.Interactivity.BehaviorCollection'.

This is because when using {x:Bind ...} the Behavior will set the resolvedSource internally to the parent container, which is resolved by the parent class Behavior because {x:Bind ...} is used.
If you use {Binding ...} this problem will not occur and therefor workaround till the {x:Bind ...} is supported.

The root cause of this is the SourceObjectProperty PropertyMetadata.

Test case:

Xaml:

<Page ... >
    <Grid>
        <Button Name="TestButton" />
        <i:Interaction.Behaviors>
            <!-- Does not work -->
            <c:EventTriggerBehavior SourceObject="{x:Bind TestButton}" EventName="Click" />
            <!-- Does work -->
            <!-- <c:EventTriggerBehavior SourceObject="{Binding ElementName=TestButton}" EventName="Click" /> -->
        </i:Interaction.Behaviors>
    </Grid>
</Page>

The following will then happen in EventTriggerBehavior when the page is being loaded:
1. EventName binding triggering OnEventNameChanged setting the event name
2. OnAttached is triggered and does ReadLocalValue to check against DependencyProperty.UnsetValue, because this is true it sets the resolvedSource to the parent Grid.
3. OnAttached invokes SetResolvedSource which will invoke RegisterEvent because the resolvedSource is not null.
4. RegisterEvent code will throw an exception in because the event cannot be found in the sourceObjectType.

The different between {x:Bind ...} and {Binding ...} is that at 2 that {x:Bind ...} The ReadLocalValue returns in the beginning DependencyProperty.UnsetValue, but with {Binding ...} the value null.

A fix for this issue would be changing the default value of SourceObjectProperty PropertyMetadata with DependencyProperty.UnsetValue.
Or instead of a ReadLocalValue for DependencyProperty.UnsetValue a normal check against null because the target is almost always a binding or code assigned value?

NavigationCacheMode causes problems with InvokeCommandAction

Hello,

I use InvokeCommandAction in order to invoke command from a page. Everything works very well, however, if I enable NavigationCacheMode on a page then I start to have a trouble.

Example
The first page has NavigationCacheMode="Enabled" and contains some InvokeCommandAction. If I navigate to different page, then I go back, the InvokeCommandAction is called twice.

xmlns:i="using:Microsoft.Xaml.Interactivity"
xmlns:iCore="using:Microsoft.Xaml.Interactions.Core"

<GridView ...>
    <i:Interaction.Behaviors>
        <iCore:EventTriggerBehavior EventName="ItemClick">
            <iCore:InvokeCommandAction Command="{Binding MyCommand}" />
        </iCore:EventTriggerBehavior>
    </i:Interaction.Behaviors>
</GridView>

// I use MVVM Light Toolkit
public RelayCommand MyCommand { get; private set; }
MyCommand = new RelayCommand(() => {  ... });

InvokeCommandAction exception when CommandParameter is NULL

I have a GridView hooked up to an observable collection of type Person ( POCO ).
I want to reroute the tapped event to a command in my viewmodel through use of InvokeCommandAction.
By using this I also use a CommandParameter, this is bound to a SelectedPerson ( of type Person ) property on the viewmodel in TwoWay mode ( general binding no x:Bind ).

If the selectedPerson is NULL and the Observable collection is NULL you'll get an invalid cast exception of the TappedRoutedEventArgs to Person.

I would have thought I would get NULL as input in my method ( that is linked to the command ).

Changing every reference to Person in this chain to object fixes the problem, but that would not be that great I guess.
Also when there are items in the observable collection everything works.

Repo: https://github.com/Depechie/TapCommand
Due to issue #102 I was unable to test this with the samples project to debug myself...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.