microsoft / xamlbehaviorswpf Goto Github PK
View Code? Open in Web Editor NEWHome for WPF XAML Behaviors on GitHub.
License: MIT License
Home for WPF XAML Behaviors on GitHub.
License: MIT License
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
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.
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.
Hi there!
First of all thanks for the great library!
Is there something blocking you from migrating to .Net Core 3.1?
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.
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... (!)
Describe the bug
The Samples solution fails to build on fresh checkout.
To Reproduce
Steps to reproduce the behavior:
samples\XAMLBehaviorsSample\XAMLBehaviorsSample.sln
Expected behavior
Build should succeed.
Actual behavior
Build fails. See screenshot below.
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:
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:
Thoughts?
Can the latest 1.1 release be added to GitHub too please?
Perhaps with a short changelog?
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 ComparisonCondition
s, what am I doing wrong?
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Left side should look the same as the right side.
Screenshots
Here is a screenshot:
Desktop (please complete the following information):
Reproduction Link
https://github.com/Zolomon/xaml-behaviors-trigger-bug
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.
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
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.
TranslateZoomRotateBehavior set ConstrainToParentBounds="True" useless,and Changed event useless too, my project use vs2017+wpf+.net 4.5+Microsoft.Xaml.Behaviors.Wpf v1.1.19
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.
The current xmlns namespaces still reference Expression:
Since the name Expression is no longer used, these namespaces should be changed as well. For example:
http://schemas.microsoft.com/xaml/2018/behaviors
Do we need only a single namespace or should the interactivity and interactions namespaces be kept separate?
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
Desktop (please complete the following information):
Reproduction Link
XamlBehavioursExample.zip
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:
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.
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.
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.
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.
Currently nuget package gets versioned based on timestamps. Consider using Nerdbank.Gitversioning instead. See PR review comment #17 (review)
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
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:
XamlBehaviorsWpf/src/Microsoft.Xaml.Behaviors/Input/KeyTrigger.cs
Lines 74 to 81 in 7c79fe9
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?
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.
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
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):
Reproduction Link
_testHyperlinkAction.zip
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.
I have a scenario where a ConditionBehavior
would seem like a right fit but I can't figure out how to use the code. The Condition example doesn't use this Behavior. Can you throw one or two together real quick, please?
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.
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()
As described in https://social.msdn.microsoft.com/Forums/lync/en-US/f14d1486-24ba-447b-9712-e16f5457a08b/fluidmovebehavior-memory-leak-bug there is a memory leak with the static TagDictionary
.
I write this as a reminder/question, as I think this issue is still existing in the current code base.
Event properties are missing from the nuget package
XamlBehaviorsWpf/src/Microsoft.Xaml.Behaviors/InvokeCommandAction.cs
Lines 22 to 24 in 294a4bc
That means that MVVM Light's implementation is the only option for us at this time:
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:
_
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?
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.
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):
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.
<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>
Enable setting behaviors via a style or in any other way that it can be applied globally on a control.
I'm trying to set a behavior so that it applies on all TextBox
es 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.
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
Nuget Package v 1.0.30
contains debug build with assembly version number 1.0.0.0 which is lower than previous version 1.0.1.0 of package version 1.0.1
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.
Desktop (please complete the following information):
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:
'''
'''
TO
'''
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.
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):
<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>
See this page: https://github.com/Microsoft/XamlBehaviorsWpf/community
Need to add:
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.
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
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
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.
Right now the source code for the UWP behaviors is available at https://github.com/Microsoft/XamlBehaviors
This repository could potentially be merged with the XamlBehaviors repository.
Please Support of .NET Core 3
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.