79170544

Date: 2024-11-08 15:08:06
Score: 3.5
Natty:
Report link

i have same problem- i need to use Persian date picker instead of default date picker into the material design component. i try to create custom template for (and use Arash persian date picker component )it but don't work- this is my code :

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters;assembly=MaterialDesignThemes.Wpf"
                    xmlns:internal="clr-namespace:MaterialDesignThemes.Wpf.Internal;assembly=MaterialDesignThemes.Wpf"
                    xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
                    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
                    xmlns:PersianDateControls="clr-namespace:Arash.PersianDateControls;assembly=PersianDateControls">
    <ResourceDictionary.MergedDictionaries>


        <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.blue.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Secondary/MaterialDesignColor.Lime.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Shadows.xaml" />
        
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Calendar.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.TextBox.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign2.Defaults.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/MaterialDesignColor.Green.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.TextBox.xaml" />

    </ResourceDictionary.MergedDictionaries>
    <Style x:Key="MaterialDesignPersianDatePicker" TargetType="{x:Type DatePicker}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DatePicker}">
                    <Grid>
                        <!-- TextBox to display selected date -->
                        <TextBox x:Name="PART_TextBox"
                             VerticalAlignment="Center"
                             HorizontalContentAlignment="Center"
                             Style="{StaticResource MaterialDesignTextBoxStyle}"
                             IsReadOnly="True"
                             Text="{Binding SelectedDate, RelativeSource={RelativeSource TemplatedParent}, StringFormat='yyyy/MM/dd'}" />

                        <!-- Button to open Persian Date Picker popup -->
                        <Button x:Name="PART_Button"
                            HorizontalAlignment="Right"
                            VerticalAlignment="Center"
                            Style="{StaticResource MaterialDesignIconButtonStyle}"
                            >
                            <materialDesign:PackIcon Kind="Calendar" />
                        </Button>

                        <!-- Popup containing Persian Date Picker -->
                        <Popup x:Name="PART_Popup"
                           Placement="Bottom"
                           StaysOpen="False"
                           AllowsTransparency="True"
                           PlacementTarget="{Binding ElementName=PART_TextBox}">
                            <PersianDateControls:PersianCalendar
                            x:Name="PersianDatePicker"
                            SelectedDate="{Binding SelectedDate, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
                            Background="{DynamicResource MaterialDesignPaper}"
                            BorderBrush="{DynamicResource MaterialDesignDivider}"
                            BorderThickness="1" />
                        </Popup>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <!-- Optional: Add additional Material Design properties for colors, padding, etc. -->
    </Style>


</ResourceDictionary>

Reasons:
  • Blacklisted phrase (0.5): i need
  • Blacklisted phrase (1): i have same problem
  • Long answer (-1):
  • Has code block (-0.5):
  • Me too answer (2.5): i have same problem
  • Low reputation (1):
Posted by: Hassan