Coder Social home page Coder Social logo

xamlbehaviorswpf's Introduction

XamlBehaviors for WPF

XAML Behaviors is an easy-to-use means of adding common and reusable interactivity to your WPF applications with minimal code. Use of XAML Behaviors is governed by the MIT License. We are working with a committee of Microsoft MVP leaders to guide the Behaviors project and evaluate incoming pull requests.

Getting Started

Where to get it

Resources

More Info

Using Behaviors SDK

To use behaviors in your project, add the Microsoft.Xaml.Behaviors.Wpf NuGet package to your project.

Buiding Behaviors from Source

What You Need

Clone the Repository

Build and Create XAML Behaviors NuGet

  • Open a Visual Studio developer command prompt
  • Navigate to the XAML Behaviors for WPF repository
  • Run msbuild src\Microsoft.Xaml.Behaviors\Microsoft.Xaml.Behaviors.csproj /t:Pack

Contributing

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

xamlbehaviorswpf's People

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

xamlbehaviorswpf's Issues

Advertising WPF behaviors package in Blend

Details about Problem

From within Blend, users should have a way to easily add new WPF behaviors NuGet package to a project similar to the way UWP projects have a link to add the UWP behaviors NuGet package.

image

Use Case

  1. User does not have any behaviors available for the project. In this case, a link will display in the Behaviors section of the Assets pane with the same appearance as for UWP. This link will install the WPF behaviors package.
  2. User already has behaviors available old behaviors SDK from a previous version of Visual Studio but has not added the WPF behaviors nuGet package to the project. In this case, the link will still appear but the behaviors from the SDK will appear after the link.

Detailed Repro Steps so we can see the problem

  1. Open Blend.
  2. Create a new WPF project.
  3. Open the Behaviors tab in the Assets pane.

LaunchUriOrFileAction prevent application to pass Windows App Certification Kit

Describe the bug
When WPF application packed as UWP application, and submitted to "Windows App Certification Kit" for validation, this package gives FAILED status for the application,

Error Found: The blocked executables test has detected the following errors:
File al2ka\Microsoft.Xaml.Behaviors.dll contains a reference to a "Launch Process" related API System.Diagnostics.Process.Start

even if I do not use behaviour LaunchUriOrFileAction which trigger the error

Behaviors SDK installed and WPF behaviors NuGet package added to project

Details about Problem

If a user has already installed the Blend for Visual Studio SDK for .NET and adds the Microsoft.Xaml.Behaviors.Wpf NuGet package to a project, two versions of each behavior will be available.

Use Case

When WPF Xaml behaviors are available for a project from both the Microsoft.Xaml.Behaviors.Wpf NuGet package and the Blend for Visual Studio SDK for .NET installed on a machine, the asset pane will only show the version of behaviors from the NuGet package.

The behaviors from the NuGet package have different namespaces from behaviors in the Blend for Visual Studio SDK for .NET. Any existing references to the behaviors from the Blend for Visual Studio SDK for .NET will still work and use the old behaviors. Updating to the behaviors from the NuGet package will be as simple as updating the namespace in most cases.

Detailed Repro Steps so we can see the problem

  1. Install the Blend for Visual Studio SDK for .NET component.
  2. Open or create a WPF project.
  3. Add the Microsoft.Xaml.Behaviors.Wpf NuGet package.
  4. Open a XAML page and observe the Behaviors tab of the Assets pane.

Make LaunchUriOrFileAction easier to use with Hyperlink

Describe the bug
Using LaunchUriOrFileAction together with Hyperlink feels overcomplicated.

To Reproduce
Try to use Hyperlink with LaunchUriOrFileAction. The minimum XAML to do this is AFAICT:

<!--xmlns:b="http://schemas.microsoft.com/xaml/behaviors"-->
<Hyperlink Name="link" NavigateUri="https://github.com/Microsoft/XamlBehaviorsWpf/wiki/LaunchUriOrFileAction">
    Link text goes here
    <b:Interaction.Triggers>
        <b:EventTrigger EventName="RequestNavigate">
            <b:LaunchUriOrFileAction Path="{Binding NavigateUri, ElementName=link}" />
        </b:EventTrigger>
    </b:Interaction.Triggers>
</Hyperlink>

NavigateUri has to be set because of limitations in Hyperlink -- the RequestNavigate event won't fire if NavigateUri is empty. LaunchUriOrFileAction.Path has to be set, albeit with a binding to the parent hyperlink's NavigateUri; but this means the hyperlink also needs a Name.

Expected behavior
This should be possible with a single line, as Hyperlink and this action are a natural fit together.

Desktop (please complete the following information):

  • Version with bug: 1.1.19
  • Last known working version: Unknown

Reproduction Link
_testHyperlinkAction.zip

Could not load file or assembly Microsoft.Xaml.Behaviors

Describe the bug
Using behaviors in my xaml brings compilation error message.

To Reproduce

<Window x:Class="Aveva.SplashScreen.Sample.View.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
        >
    <b:Interaction.Triggers>
        <b:EventTrigger EventName="MouseDown" >
            <b:InvokeCommandAction 
                Command="{Binding MouseDownCommand}" 
                CommandParameter="{Binding Mode=OneWay, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window }}"  />
        </b:EventTrigger>
    </b:Interaction.Triggers>

Error

System.Windows.Markup.XamlParseException: 'Could not load file or assembly 'Microsoft.Xaml.Behaviors, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'

Expected behavior
To work out of the box, without having to reference library in code behind. Because it works fine if I reference anything:

        public MainWindow()
        {
            InitializeComponent();
            
            var _ = new Microsoft.Xaml.Behaviors.DefaultTriggerAttribute(typeof(Trigger), typeof(Microsoft.Xaml.Behaviors.TriggerBase), null);
        }

Desktop (please complete the following information):

  • Version with bug: 1.1.31

How to resolve NU1202: Package Microsoft.Xaml.Behaviors.Wpf 1.1.19 is not compatible with net50-windows (.NETFramework,Version=v5.0,Profile=windows). Package Microsoft.Xaml.Behaviors.Wpf 1.1.19 supports:


Issue moved from dotnet/sdk#14371


From @mageshsankar on Thursday, October 29, 2020 12:46:18 PM

After installing the latest preview, we noticed our WPF apps targeting net50-windows will not compile. We tried to create a new project from scratch and hit the same issue. The simple project file is defined below:

<PropertyGroup>
    <OutputType>library</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
    <UseWPF>true</UseWPF>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>

Cannot restore Microsoft.Xaml.Behaviors.Wpf 1.1.19 package

Event properties are missing from the nuget package

Event properties are missing from the nuget package

public static readonly DependencyProperty EventArgsConverterProperty = DependencyProperty.Register("EventArgsConverter", typeof(IValueConverter), typeof(InvokeCommandAction), new PropertyMetadata(null));
public static readonly DependencyProperty EventArgsConverterParameterProperty = DependencyProperty.Register("EventArgsConverterParameter", typeof(object), typeof(InvokeCommandAction), new PropertyMetadata(null));
public static readonly DependencyProperty EventArgsParameterPathProperty = DependencyProperty.Register("EventArgsParameterPath", typeof(string), typeof(InvokeCommandAction), new PropertyMetadata(null));

That means that MVVM Light's implementation is the only option for us at this time:

KeyTrigger: KeyUp command action is not fired for the modifier keys

Summary

The following definition does not result into the invocation of a command

<b:KeyTrigger Key="LeftCtrl" FiredOn="KeyUp">
    <b:InvokeCommandAction Command="..." />
</b:KeyTrigger>

(That same behavior is for any modifier key.)

To reproduce

  • Build and run the following WPF app project (.NET Framework 4.7.2): KeyTriggerDemo.zip
  • Press the LEFT CTRL key several times

Expected behavior: Two lines are displayed: "UP UP UP..." and "DOWN DOWN DOWN..."
Observed behavior: No "UP"s are displayed.

Reason

The root cause is in the KeyTrigger.cs file:

private void OnKeyPress(object sender, KeyEventArgs e)
{
if (e.Key == this.Key &&
Keyboard.Modifiers == GetActualModifiers(e.Key, this.Modifiers))
{
this.InvokeActions(e);
}
}

When the CTRL key is UP, the Keyboard.Modifiers is None (at least it has CTRL off), however GetActualModifiers returns the instance with CTRL on. Thus, the if condition returns false and actions are not invoked.

Is that by design or a bug?

ArgumentException: "EventTrigger" is not a valid type for the TriggerType parameter. Make sure "EventTrigger" derives from TriggerBase

I have plus button in my wpf application when I click that button it opens another tab. Recently we change system.windows.interactivity.dll to Microsoft.Xaml.Behaviors.dll. after this I m getting following error. Any idea how to solve this issue.
System.Windows.Markup.XamlParseException
HResult=0x80131501
Message='Add value to collection of type 'Microsoft.Xaml.Behaviors.TriggerCollection' threw an exception.' Line number '132' and line position '60'.
Source=PresentationFramework
Inner Exception 1:
ArgumentException: "EventTrigger" is not a valid type for the TriggerType parameter. Make sure "EventTrigger" derives from TriggerBase.

Set behaviors globally

Feature request

Enable setting behaviors via a style or in any other way that it can be applied globally on a control.

Description

I'm trying to set a behavior so that it applies on all TextBoxes in my application via a global style.

I've tried the following:

<Style TargetType="TextBox">
  <Setter Property="b:Interaction.Behaviors">
    <Setter.Value>
      <local:DataAnnotationsBehavior/>
    </Setter.Value>
  </Setter>
</Style>

But I get this error:

XDG0041: The property "Behaviors" is not a DependencyProperty. To be used in markup, non-attached properties must be exposed on the target type with an accessible instance property "Behaviors". For attached properties, the declaring type must provide static "GetBehaviors" and "SetBehaviors" methods.

My suggestion is that you make a DependencyProperty out of the Behaviors property or enable applying it globally somehow.

'Interaction.Triggers' does not exist

Describe the bug
received this error after upgrading to 1.1.19 in Microsoft Visual Studio Community 2019
Version 16.4.3

microsoft.xaml.behaviors 'Interaction.Triggers' does not exist in XML namespace 'http://schemas.microsoft.com/xaml/behaviors'

To Reproduce
I loaded all previous packages and up to 1.1.3 and they work.

Expected behavior
no build errors

Desktop (please complete the following information):

  • Version with bug: Windows 10 home 1903

<Window x:Class="GS.ChartViewer.MainWindowV"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" TextElement.FontSize="14" ResizeMode="CanResizeWithGrip" WindowStyle="None"
xmlns:properties="clr-namespace:GS.ChartViewer.Properties"
xmlns:controls="clr-namespace:GS.ChartViewer.Controls"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:local="clr-namespace:GS.ChartViewer"
xmlns:Interactions="http://schemas.microsoft.com/xaml/behaviors"
xmlns:shared="clr-namespace:GS.Shared;assembly=GS.Shared"
xmlns:enums="clr-namespace:LiveCharts.Geared;assembly=LiveCharts.Geared"
xmlns:helpers="clr-namespace:GS.ChartViewer.Helpers"
...
Interactions:Interaction.Triggers
<Interactions:EventTrigger EventName="PreviewMouseLeftButtonUp">
<Interactions:InvokeCommandAction Command="{Binding ClickPulsesSeriesCmd}" CommandParameter="{Binding ElementName=ListView1, Path=SelectedItem}"/>
</Interactions:EventTrigger>
</Interactions:Interaction.Triggers>

Publish the private key

You should not be using a private key for strong name signing an open source project. It causes all sorts of problems, like you can't just build and run the unit tests, because you hit strong name assembly mismatch.
See doc here: https://docs.microsoft.com/en-us/dotnet/framework/app-domains/strong-named-assemblies

If you are an open-source developer and you want the identity benefits of a strong-named assembly, consider checking in the private key associated with an assembly into your source control system.

Allow Task as ReturnType in CallMethodAction

Is your feature request related to a problem? Please describe.
Binding to Methods is limited to void (void as well as async void is possible). See this example:

<b:Interaction.Triggers>
    <b:EventTrigger EventName="PreviewMouseDown">
        <behavior:CustomCallMethodAction MethodName="OnSomeEventThatOccuredAsync"
                            TargetObject="{Binding}" />
    </b:EventTrigger>
</b:Interaction.Triggers>

public async void OnSomeEventThatOccuredAsync(object sender, EventArgs eventArgs){...}

It would be nice to be able to handle a Task instead of void.

Describe the solution you'd like
In CallMethodAction.cs there is a restriction to void:

private bool IsMethodValid(MethodInfo method)
{
    if (!string.Equals(method.Name, this.MethodName, StringComparison.Ordinal))
    {
        return false;
    }

    if (method.ReturnType != typeof(void)) // <-- here
    {
        return false;
    }

    return true;
}

Might it be feasable to allow ReturnType Task also? In my simple solution where I wanted it there was no problem when I changed the specific lines to:

if (method.ReturnType != typeof(void) && method.ReturnType != typeof(Task))
{
    return false;
}

The upcoming calls (especially the invoke() call) worked as expected although I'm not finally sure if there should be a switch to await the task result maybe. I think not but my spare time does not allow a further investigation.

Describe alternatives you've considered
Using async void... (!)

Additional context

DataTrigger: Evaluate the binding's initial value like WPF

I have a class that overrides DataTrigger's OnAttached/OnDetaching methods to subscribe/unsubscribe to the AssociatedObject's Loaded event so I can call EvaluateBindingChange to set the initial value of the DataTrigger similar to WPF.

System.Reflection.TargetInvocationException: Checkbox event fires when used in datagrid w/o virtualiztion when scrolling

When using this library for events on datagrids, it will automatically fire off event if the datagrid is virtualized. Setting VirtualizingPanel.IsVirtualizing to false will stop the behavior but you will lose too much performance.

Below is a sample project to reproduce the behavior.

Steps to reproduce:

  1. Click load employees
  2. Click the checkbox on ID 1
  3. Click the checkbox on ID 2
  4. Scroll all the way down
  5. Scroll all the way up

https://github.com/cflint987/WpfBug

Suggest to change XmlnsPrefix casing to lowercase.

I suggest to change the XmlnsPrefix from Interactions to interactions since other libraries uses lower case to and ReSharper suggests me to change the casing to lowercase.

Name 'Interactions' does not match rule 'Namespace alias'. Suggested name is 'interactions'.

PR referenced: #28

Wiki-Update suggestion for ConditionBehavior.md

I wasn't able to suggest edits for the Wiki itself, so I suggest to update the Wiki for ConditionBehavior.md with the following example:

ConditionBehavior attaches to a trigger and controls the conditions on which to fire the actions.

This behavior blocks an action from occurring if the specified Condition returns false.

SampleCode

XAML

<Button x:Name="Button">
  <Behaviors:Interaction.Triggers>
    <Behaviors:EventTrigger EventName="Click" SourceObject="{Binding ElementName=Button}">
      <b:Interaction.Behaviors>
        <b:ConditionBehavior>
          <b:ConditionalExpression>
            <b:ComparisonCondition LeftOperand="{Binding Path=Items.Count, ElementName=TabControl}" RightOperand="0" />
          </b:ConditionalExpression>
        </b:ConditionBehavior>
      </b:Interaction.Behaviors>
      <Behaviors:ChangePropertyAction TargetObject="{Binding ElementName=DataTriggerRectangle}" PropertyName="Fill" Value="LightYellow"/>
    </Behaviors:EventTrigger>
  </Behaviors:Interaction.Triggers>
</Button>

Setup a CI build

We need to setup a CI build that will run all tests for submitted PRs. We should also publish any CI builds to a separate feed such as MyGet so developers can test the latest feature to provide feedback.

Application.LoadComponent exception for XAML resource

Describe the bug
Loading a XAML resource file (no code behind), using Application.LoadComponent, fails with a XAML load exception.

To Reproduce
Steps to reproduce the behavior:

  1. Add a XAML file to a WPF .NET Core 3.0 project
  2. Add the Interaction.Triggers element below the Window element
  3. Remove the code behind
  4. Make project Build Action=Resource for the file
  5. Use Application.LoadComponent to load the resource at startup
  6. Exception: Cannot set unknown member '{http://schemas.microsoft.com/xaml/behaviors}Interaction.Triggers'

Expected behavior
The component is loaded without an exception occurring.

Reproduction Link
https://github.com/Statical/issue-load-microsoft-xaml-behaviors-wpf

Background
Trying to upgrade a WPF application written in F# to .NET Core 3.0 - the issue occurs in C# as well, though -- but in C# projects one would typically set the build action for XAML to Resource and instead use Page. This has not been possible with F# projects.

Migrate to .Net Core 3.1

Hi there!

First of all thanks for the great library!
Is there something blocking you from migrating to .Net Core 3.1?

Release Notes for v1.1.31

Describe the bug
The latest version released on NuGet is 1.1.31, but there is no associated release or change notes to be found in GitHub or anywhere else as far as I can tell.

To Reproduce
N/A

Expected behavior
Release notes should be available for the release.

Screenshots
N/A

Desktop (please complete the following information):
N/A

Reproduction Link
N/A

Trigger EnterActions & ExitActions

Please, implement actions in triggers when the condition is NOT fulfilled, so that you would not have to write 2 separate triggers in Xaml. Like the ones implemented in WPF DataTrigger.EnterActions and DataTrigger.ExitActions. It would be very convenient. Thanks.

TriggerAction not invoked when CustomEventArgs do not inherit from EventArgs

I just went over this article The Updated .NET Core Event Pattern in the docs which states that custom EvventArgs do not have to inherit from EventArgs any more.

I wrote following CustomControl defining CustomEvent1 with CustomEvent1Args to try it out:

public partial class Part2UserControl
{

    public event EventHandler<CustomEvent1Args> CustomEvent1;


    public Part2UserControl()
    {
        InitializeComponent();
        ControlCanvas.PreviewMouseLeftButtonUp += ControlCanvas_PreviewMouseLeftButtonUp;
    }

    private void ControlCanvas_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        CustomEvent1?.Invoke(sender, new CustomEvent1Args(new Point(13,37)));
    }

}

public class CustomEvent1Args /*: EventArgs*/
{
    public Point Position { get; }

    public CustomEvent1Args(Point position)
    {
        Position = position;
    }

}

And I bound a command to the CustomEvent1 like this:

<local:Part2UserControl Width="100" Height="100" HorizontalAlignment="Left">
    <i:Interaction.Triggers>
    <i:EventTrigger EventName="CustomEvent1">
        <utils:TriggerActionCommand Command="{Binding CustomEventCommand}" />
    </i:EventTrigger>
    </i:Interaction.Triggers>
</local:Part2UserControl>

Using this implementation of TriggerActionCommand:

public class TriggerActionCommand : TriggerAction<DependencyObject>
{

    #region Dependency Properties

    /// <summary>
    /// Command DP
    /// </summary>
    public static readonly DependencyProperty CommandProperty = DependencyProperty.RegisterAttached("Command", typeof(ICommand), typeof(TriggerActionCommand), new FrameworkPropertyMetadata((ICommand)null));

    /// <summary>
    /// Command that should be called when event is triggered.
    /// </summary>
    public ICommand Command
    {
        get => (ICommand)GetValue(CommandProperty);
        set => SetValue(CommandProperty, value);
    }

    /// <summary>
    /// CommandParameter DP
    /// </summary>
    public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.RegisterAttached("CommandParameter", typeof(object), typeof(TriggerActionCommand), new FrameworkPropertyMetadata((object)null));

    /// <summary>
    /// CommandParameter which should be passed with the Command.
    /// </summary>
    public object CommandParameter
    {
        get => GetValue(CommandParameterProperty);
        set => SetValue(CommandParameterProperty, value);
    }

    #endregion

    /// <summary>
    /// Invokes the action.
    /// </summary>
    /// <param name="parameter">The parameter to the action. If the action does not require a parameter, the parameter may be set to a null reference.</param>
    protected override void Invoke(object parameter)
    {
        ICommand command = Command;
        object commandParameter = CommandParameter;

        //If an aditional command parameter is specified construct a tuple
        if (commandParameter != null)
            parameter = (parameter, commandParameter);

        if (command?.CanExecute(parameter) == true)
            command.Execute(parameter);
    }

The problem is now that when CustomEvent1Args does not inherit from EventArgs, the Invoke(object parameter) method of the TriggerAction is not called. When CustomEvent1Args inherits from EventArgs everything works as expected.

Event Binding Markup Extension

Is your feature request related to a problem? Please describe.
Attached behaviours work fine but are a little cumbersome and long-winded compared to bindings.

Describe the solution you'd like
Like with {Binding ...} markup on properties, allow {EventBinding ...} on events which offers the same mechanisms as event triggers (InvokeCommandAction with EventArgsConverter in particular). So rather than:

<MyControl>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MyEvent">
            <i:InvokeCommandAction Command="{Binding MyCommand}" EventArgsConverter="{StaticResource MyConverter}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</MyControl>
<MyControl MyEvent="{i:EventBinding MyCommand, Converter={StaticResource MyConverter}}"/>

Describe alternatives you've considered
I have seen 2 or 3 implementations of this idea in nuget, but they don't work as nicely as the mechanism used by behaviours (either too simple or over-complicated).

Additional context
Add any other context or screenshots about the feature request here.

Provide a link to the official NuGet package in readme.md

History:
System.Windows.Interactivity has never been published by Microsoft as a NuGet package,
thus making it hard to use across shared projects published as NuGet packages themselves, since you had do choose from one of the hundreds inofficial packages dangling around at NuGet.org or publish your own inofficial version.

To avoid this situation with Microsoft.Xaml.Behaviors, this repo should clearly point out the official NugGet package.

Actually its not really clear if https://www.nuget.org/packages/Microsoft.Xaml.Behaviors.Wpf is the official NuGet package provided and maintained by Microsoft.
The package claims Microsoft as one of its owners, but there is no back link from this Repo to NuGet.

Samples solution fails to build on fresh checkout

Describe the bug
The Samples solution fails to build on fresh checkout.

To Reproduce
Steps to reproduce the behavior:

  1. Download XamlBehavioursWpf as a zip
  2. Unzip
  3. Open samples\XAMLBehaviorsSample\XAMLBehaviorsSample.sln
  4. Build or rebuild solution.

Expected behavior
Build should succeed.

Actual behavior
Build fails. See screenshot below.

Screenshots
behaviors

Allow EventTrigger to bind to Action events

Is your feature request related to a problem? Please describe.
I don't like using full event handlers when I have no need for the sender or eventargs, so I use event Action, but EventTrigger doesn't support these.

Describe the solution you'd like
I feel this is akin to having parameterless methods as event handlers, which IS supported. Potentially an action with arguments might also be desirable, but would require type checking the arguments on the target method to make sure they match the event. I would be happy with just supporting Action with no arguments, but allowing Action<T> (like eventargs without sender, but any type) would be helpful too.

Describe alternatives you've considered
Only alternative is to use full event handlers or write my own trigger that does this.

No support for .NET Framework 4.0

Description
Adding Microsoft.Xaml.Behaviors.Wpf from NuGet to a WPF .NET Framework 4.0 application fails with the error:

Could not install package 'Microsoft.Xaml.Behaviors.Wpf 1.0.1'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

The NuGet description does not show any specific dependencies to a .NET Framework version. If the .NET Framework 4.0 is not truly supported, this should be made clear somewhere.

Expected behavior
NuGet package is properly referenced and added to the "References" list of the project. If .NET Framework 4.0 is not meant to be supported, this should be made clear in the NuGet description.

PropertyChangedTrigger with ConditionalExpression does not work. DataTrigger does work.

Describe the bug
I am trying to use a ContentPresenter together with a PropertyChangedTrigger in Interactivity.Triggers to set its ContentTemplate property dynamically based on multiple conditions. I could not get this to work, so I tried using only a single condition. I could not get this to work either, however using DataTriggers works but they are limited to single value comparisons (I am aware that I can make computed properties that hides the multiple condition).

Link at the bottom to a git repo that reproduces my case.

I need to use multiple ComparisonConditions, what am I doing wrong?

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://github.com/Zolomon/xaml-behaviors-trigger-bug
  2. Run the application locally
  3. See error

Expected behavior
Left side should look the same as the right side.

Screenshots
Here is a screenshot:

Desktop (please complete the following information):

  • Version with bug: 1.1.0.0
  • Last known working version: ????

Reproduction Link
https://github.com/Zolomon/xaml-behaviors-trigger-bug

LaunchUriOrFileAction fails in .NET Core 3

Using LaunchUriOrFileAction with WPF on NETCore3 Preview 1 throws the exception below:

System.ComponentModel.Win32Exception
  HResult=0x80004005
  Message=The system cannot find the file specified.
  Source=System.Diagnostics.Process
  StackTrace:
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start(String fileName)
   at Microsoft.Xaml.Behaviors.Core.LaunchUriOrFileAction.Invoke(Object parameter)
   at Microsoft.Xaml.Behaviors.TriggerAction.CallInvoke(Object parameter)
   at Microsoft.Xaml.Behaviors.TriggerBase.InvokeActions(Object parameter)
   at Microsoft.Xaml.Behaviors.EventTriggerBase.OnEvent(EventArgs eventArgs)
   at Microsoft.Xaml.Behaviors.EventTriggerBase.OnEventImpl(Object sender, EventArgs eventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.EventRoute.ReInvokeHandlers(Object source, RoutedEventArgs args)
   at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
   at System.Windows.UIElement.CrackMouseButtonEventAndReRaiseEvent(DependencyObject sender, MouseButtonEventArgs e)
   at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at BehaviorsOnCore.App.Main()

InvokeCommandAction - add additional properties for more MVVM scenarios

I would like to suggest we add some additional properties to the InvokeCommandAction to make it more useful in WPF applications using the MVVM pattern.

Suggested properties:

  • EventArgsParameterPath - a path to extract a property value from the EventArgs instance to pass to the ICommand as the command parameter.
  • EventArgsConverter - a converter to convert the event args to a more friendly type meant for ViewModel consumption.
  • EventArgsConverterParameter - an argument passed as parameter to the EventArgsConverter that can be used to make more complex decisions.

Thoughts?

Strong name validation failed loading the design time assembly

Describe the bug
General output shows exception message when using XamlBehaviorsWpf.
Designer and Program do work as intended.

To Reproduce
Steps to reproduce the behavior:
1.Load Solution/Project containing reference on Microsoft.Xaml.Behaviors.Wpf
2. Open Output->General
3. See error

There was an exception when loading the design time assembly 
C:\Users\%USERNAME%\AppData\Local\Microsoft\VisualStudio\16.0_c41b5f41\Designer\ShadowCache\o23at5zu.4ir\bc0jsohr.34f\Design\Microsoft.Xaml.Behaviors.Design.dll':`
Strong name validation failed. (Exception from HRESULT: 0x8013141A)

Expected behavior
No error

Screenshots
Error_StrongNameValidation

Desktop (please complete the following information):

  • Windows: Windows 10 Enterprise v1809
  • Microsoft Visual Studio Professional 2019
    Version 16.9.0
    VisualStudio.16.Release/16.9.0+31025.194
    Microsoft .NET Framework
    Version 4.8.03761
  • Target Framework: .NET Framework 4.5.2
  • Version with bug: 1.1.31
  • Last known working version: /

Reproduction Link
XamlBehavioursExample.zip

Add .netcore3.0 build Target

Please add an explicit netcoreapp3.0 Target to ensure compatibility.

I've done this with WPF class libs before, so feel free to assign to me and I'll submit a PR.

Update EditorConfig

Is your feature request related to a problem? Please describe.
The current editorconfig rules are implementing coding standards that I do not agree with.

Describe the solution you'd like
I would like to open a dialog about which rules we should update to the editorconfig file to alig the coding standards more inline with modern development practices.

Describe alternatives you've considered
Some examples of items I would like to change:

  • private variables should start with an underscore _
  • else/else if statements should be on a newline (currently the are inline)

Here is the editorconfig we used for the UWP behvaiors:
https://github.com/Microsoft/XamlBehaviors/blob/master/src/BehaviorsSDKManaged/.editorconfig

We could just use that if we want.

Thoughts?

Design Time Error (XamlObjectWriterException: Collection property 'System.Windows.Controls.TextBox'.'Triggers' is null)

Describe the bug
I am getting a design time error using Interaction.Triggers in a data grid (see code at bottom). When the program is run it doesn't have any issues. I just can't see the User Control window in Visual Studio (see screenshot below).

To Reproduce
Steps to reproduce the behavior:
Error occurs at Design Time but when I remove or comment out the triggers the error goes away.
'''XAML
<i:Interaction.Triggers x:Uid="SSTriggers">
<i:EventTrigger EventName="LostFocus" >
<i:InvokeCommandAction Command="{Binding ElementName=SSLItemControl,
Path=DataContext.saveParamterizedCommand}" CommandParameter="{Binding}"/>
</i:EventTrigger>
<i:KeyTrigger Key="Enter">
<i:InvokeCommandAction Command="{Binding ElementName=SSLItemControl,
Path=DataContext.saveParamterizedCommand}" CommandParameter="{Binding}"/>
</i:KeyTrigger>
</i:Interaction.Triggers>
'''
Expected behavior
At design time I get the following error:
XamlObjectWriterException: Collection property 'System.Windows.Controls.TextBox'.'Triggers' is null.

Stack Trace
at System.Xaml.XamlObjectWriter.WriteGetObject()
at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)

InnerException:None

Screenshots
If applicable, add screenshots to help explain your problem.
Below is a screenshot of my preview window in Visual Studio.
image

Desktop (please complete the following information):

  • Version with bug:
    Windows 10
    Visual Studio Community 2017
    Microsoft.Xaml.Behaviors.Wpf 1.1.19

I followed the steps on this website to setup triggers:
https://devblogs.microsoft.com/dotnet/open-sourcing-xaml-behaviors-for-wpf/

**Here is a reproduction example:

https://github.com/smittynusmc/Trigger_Error_Sample.git**

Update:

The error goes away when I change the debug platform from x64 to Any CPU.

Update:

When renaming variables and removing code to get ready for git. When I changed this code:
'''

Capture

'''

TO

'''

Capture

'''

The error went away (variable names may be different). Basically when I changed the binding names to anything other than the name in View Model the error was gone.

Also, any ItemSource or DataContext in which I change the name of the Binding the error goes away

The error comes back after running the program once.

[Question] C++ Runtime Compatibilities/Migration

Edit: Wait, I just realized this is all managed code... oops. Someone feel free to reopen if there's something to add.

I develop in a hosted environment, and have explicit recommendations for which Visual Studio to use (due to C++ Runtime versions).

I understand I can change which Runtime compilers to use if I were to compile myself. I understand that in order to build from source, there are dependencies. But if I'm referencing from Nuget, are there any potential C++ Runtime compatibility issues? What C++ Runtime is used?

Per this documentation, https://docs.microsoft.com/en-us/cpp/porting/binary-compat-2015-2017, compatibility shouldn't be an issue (bar two minor exceptions).

I can't think there being problems, but just trying to do some due diligence before migrating.

Thanks.

Does Not Compile in Visual Studio 2019? error Unable to locate repository containing directory ..XamlBehaviorsWpf-master\src\Microsoft.Xaml.Behaviors'. Microsoft.Xaml.Behaviors

I download the source code.
When I tried to rebuild the soluton I Code the following compile errors:
Severity Code Description Project File Line Suppression State
Untitled

Error Unable to locate repository containing directory 'C:\Prism 7_2\XamlBehaviorsWpf-master\src\Microsoft.Xaml.Behaviors'. Microsoft.Xaml.Behaviors C:\Users\spaceradar.nuget\packages\microsoft.build.tasks.git\1.0.0-beta-63127-02\build\Microsoft.Build.Tasks.Git.targets 20

Am I missing something like some kind of restore

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.