Closed quasarea closed 1 year ago
Please provide a sample that reproduces the issue or this issue will be closed.
Had to be some mess at my side, sorry, could not replicate.
This a repro for me. It happens when the Page is in a class library. The easiest workaround is to name behavior command in the xaml.
<Behaviors:InvokeCommandAction x:Name="SelectionCommand" Command="{Binding SelectedItemsChangedCommand}"
Happens for me as well (however, I get a runtime exception similar to https://github.com/zspitz/ANTLR4ParseTreeVisualizer/issues/35#issue-505087118) when the WPF project is a class library. Interestingly when I tried to reproduce it in a fresh sample project, I wasn't able to. Perhaps there is something else that is interfering with it. May dig deeper if I get more time
Like @quasarea mentioned, a quick fix is to simply reference something from within the Microsoft.Xaml.Behaviors
package before the call to the Window
's InitializeComponent()
Hi,
Same problem with version 1.1.37 of the Microsoft.Xaml.Behaviors Library !
Just added this in the CTOR of the control where I use it:
public MyControl() { var trig = new Microsoft.Xaml.Behaviors.EventTrigger(); trig.SourceName = "foo"; // InitializeComponent(); }
And no error after that !
I have the OPs same problem using version 1.1.39. The view is simply a Window in a folder in a class library. The library is a plug-in for another application. Creating a new WPF application and loading in that app as a plugin to the host app does not have this exception.
I was able to use OPs work around and view now works:
public MainWindow()
{
InitializeComponent();
var _ = new Microsoft.Xaml.Behaviors.DefaultTriggerAttribute(typeof(Trigger), typeof(Microsoft.Xaml.Behaviors.TriggerBase), null);
}
I have the same issue when trying to add a ChangePropertyAction
in page located in a referenced class library.
Adding a x:Name
to the action solved the problem as @Jebarson recommended.
Currently having the same issue. Using it on a class library. var _ = new Microsoft.Xaml.Behaviors.DefaultTriggerAttribute(typeof(Trigger), typeof(Microsoft.Xaml.Behaviors.TriggerBase), null); This does the trick for me as well, wondering is there has been a fix for this or if there is a cleaner way. I will most likely have multiple wpf windows that will requiere access to triggers and I dont want to add this line of code to every single one.
Any help is appreciated.
Same issue, I installed the NuGet pkg and tried to use this interaction logic:
...
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
...
...
<Button Content="Button 1">
<b:Interaction.Triggers>
<b:EventTrigger EventName="Click">
<b:InvokeCommandAction Command="{Binding Button1Command}" PassEventArgsToCommand="True" />
</b:EventTrigger>
</b:Interaction.Triggers>
</Button>
...
Same issue, For a net48 WPF project, Doesnt occur on class libaries net48 though.
Describe the bug Using behaviors in my xaml brings compilation error message.
To Reproduce
Error
Expected behavior To work out of the box, without having to reference library in code behind. Because it works fine if I reference anything:
Desktop (please complete the following information):