Hi,
I have a simple WinUI application to try MultiBinding. When I run debug the application, it throws error
System.AccessViolationException
.
![User's image](https://learn-attachment.microsoft.com/api/attachments/313eba7e-425d-4465-904c-cb3248c6a51d?platform=QnA)
As I researched, an AccessViolationException
is an exception typically raised when your process tries to access memory that's not its own. But I don't access to any external memory. Here is my code using MultiBinding:
<Window
x:Class="MultiBindingItem.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="using:MultiBindingItem.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:local="using:MultiBindingItem"
xmlns:local1="using:MultiBindingItem.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.Resources>
<converters:ArrayCloneConverter x:Key="ArrayCloneConverter" />
</Grid.Resources>
<Grid.DataContext>
<local:MainWindowViewModel />
</Grid.DataContext>
<StackPanel Margin="8">
<TextBox x:Name="FirstNameTextBox" Header="First Name" />
<ToggleSwitch x:Name="LastNameToggleSwitch" Header="Last Name" />
<Button Command="{Binding ClickCommand}" Content="My Button">
<interactivity:Interaction.Behaviors>
<local:MultiBindingBehavior
Converter="{StaticResource ArrayCloneConverter}"
Mode="TwoWay"
PropertyName="CommandParameter">
<local:MultiBindingItem Value="{Binding Text, ElementName=FirstNameTextBox, Mode=TwoWay}" />
<local:MultiBindingItem Value="{Binding IsOn, ElementName=LastNameToggleSwitch, Mode=TwoWay}" />
</local:MultiBindingBehavior>
</interactivity:Interaction.Behaviors>
</Button>
</StackPanel>
</Grid>
</Window>