WPF MATERIAL DESIGN LISTBOX - HELP

1 posts, 0 answers
  1. JR
    JR avatar
    1 posts
    Member since:
    May 2019

    Posted 25 May 2019 Link to this post

    Hi Guys

    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>

     

Back to Top