none
WPF MATERIALDESIGN LISTBOXITEM ISSUE RRS feed

  • Question

  • I really desperately need your help on this. I have created listbox with a toggle from materialdesign theme package and along with richtextbox. The listbox comprises of three listboxitems which are bold, italic and underline. So when the user clicks on the button and the highlighted text in the richtextbox will reflect its changes accordingly, i.e. normal font text changes to font bold.

    However what I have noticed the listboxitem with button like format has to be double clicked in order to get the font text to change from bold to normal, vice versa from normal to bold. I have been struggling on how to get the single click selection and the button to show the selected highlight colour etc.

    I couldn't use the event setter as it messes the highlight colour and styling of the listboxitems

    PLEASE HELP - the code behind is C#

    <Window x:Class="WPFDEMO.MainWindow"
    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"
    xmlns:materialDesign="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
    mc:Ignorable="d"
    TextElement.Foreground="{DynamicResource MaterialDesignBody}"
    TextElement.FontWeight="Regular"
    TextElement.FontSize="13"
    TextOptions.TextFormattingMode="Ideal"
    TextOptions.TextRenderingMode="Auto"
    Background="{DynamicResource MaterialDesignPaper}"
    FontFamily="{DynamicResource MaterialDesignFont}"
            xmlns:local="clr-namespace:WPFDEMO"
            Title="MainWindow" Height="1080" Width="1920">
        <!--<Window.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Button.xaml" />
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Window.Resources>-->
        <Grid>
            <DockPanel>
                <StackPanel DockPanel.Dock="Top">
                        <ListBox SelectionMode="Extended"
                        Style="{StaticResource MaterialDesignToolToggleFlatListBox}" 
                        Background="Transparent" materialDesign:ListBoxAssist.IsToggle="True">
                        <!--<ListBox.ItemContainerStyle>
                            <Style TargetType="ListBoxItem">
                                <EventSetter Event="PreviewMouseDown" Handler="ItemOnPreviewMouseDown"></EventSetter>
                                <EventSetter Event="PreviewMouseDoubleClick" Handler="ItemOnPreviewMouseDown"></EventSetter>
                            </Style>
                        </ListBox.ItemContainerStyle>-->
                        <ListBoxItem x:Name="btnBold" Selected="btnBold_Selection" PreviewMouseDown="btnBold_PreviewMouseDown">
                            <materialDesign:PackIcon Kind="FormatBold" />
                        </ListBoxItem>
                        <ListBoxItem x:Name="btnItalic" Selected="btnItalic_Selected">
                            <materialDesign:PackIcon Kind="FormatItalic" />
                        </ListBoxItem>
                        <ListBoxItem x:Name="btnUnderline" Selected="btnUnderline_Selected">
                            <materialDesign:PackIcon Kind="FormatUnderline" />
                        </ListBoxItem>
                    </ListBox>
                </StackPanel>
                <RichTextBox x:Name="rtbTextbox" SelectionChanged="rtbTextbox_SelectionChanged"></RichTextBox>
            </DockPanel>
        </Grid>
    </Window>

    Saturday, May 25, 2019 7:39 PM

All replies


  • Hi  CHARON1X,

    >>I really desperately need your help on this. I have created listbox with a toggle from materialdesign theme package and along with richtextbox. The listbox comprises of three listboxitems which are bold, italic and underline. So when the user clicks on the button and the highlighted text in the richtextbox will reflect its changes accordingly, i.e. normal font text changes to font bold.

    I suggest you can go to the MaterialDesignThemes and issue center for getting suitable help.

    Thank you for your understanding.

    Best regards

    Yong Lu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 27, 2019 8:09 AM