MaterialDesignInXAML / MaterialDesignInXamlToolkit

Google's Material Design in XAML & WPF, for C# & VB.Net.
http://materialdesigninxaml.net
MIT License
15.15k stars 3.43k forks source link

ListBoxAssist.IsToggle #3188

Closed jbooth88 closed 1 year ago

jbooth88 commented 1 year ago

Bug explanation

When ListBoxAssist.IsToggle=True, clicking on a list box item while a text box has focus, the LostFocus event will not trigger. Setting ListBoxAssist.IsToggle=False will trigger the LostFocus event as expected, when clicking on another item in the list.

This is a problem because when the focused text box UpdateSourceTrigger=LostFocus, the datacontext changes without updating the source, and any changes made by the user are lost.

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="144" />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>

    <ListBox 
        Grid.Column="0" 
        ItemsSource="{Binding Items, Mode=OneTime}" 
        SelectedItem="{Binding SelectedItem, Mode=TwoWay}"         
        wpf:ListBoxAssist.IsToggle="True"
        Style="{DynamicResource MaterialDesignListBox}"
        />

    <Grid Grid.Column="1" DataContext="{Binding SelectedItem, Mode=OneWay}">
        <TextBox
            md:HintAssist.Hint="Test"
            Text="{Binding BoundProperty, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
            Style="{DynamicResource MaterialDesignFloatingHintTextBox}" 
            />
    </Grid>
</Grid>

Version

4.8.0

nicolaihenriksen commented 1 year ago

@jbooth88 You are correct that there is an issue in this area. I believe my comment here can provide input on what is needed to fix it. Feel free to open up a PR with the fix if you have time.