How to fix System.AccessViolationException?

Nhan Tran 0 Reputation points
2024-01-25T09:30:23.9133333+00:00

Hi, I have a simple WinUI application to try MultiBinding. When I run debug the application, it throws error System.AccessViolationException. User's image

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>

Windows development Windows App SDK
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jeanine Zhang-MSFT 11,356 Reputation points Microsoft External Staff
    2024-01-26T02:20:40.13+00:00

    Hello,

    Welcome to Microsoft Q&A!

    According to the thread: WinUI Multibinding Support

    It seems that Winui3 does not support MultiBinding at this time.

    Thank you.

    Jeanine


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.