如何在日历的文本框中保存内容[WPF]

时间:2016-07-20 09:28:14

标签: c# .net wpf

请帮助我..我是WPF计划的新手。

我正在使用Jarloo日历来节省一些编码时间。 我有资源字典,其中包含我的日历主题。 日历是可编辑的,我可以在每个日期分别输入文本或做笔记。问题是textbox位于ResourceDictionary 我打算保存文本并使用

将代码放在MainWindow.cs上
Properties.Settings.Default.(nameofmysetting) = (NameofthetextboxInsideTheResourceDictionary).Save();

但我无法访问资源字典。我只想保存我制作的文字 当我打开我的日历时,它仍然存在,文本保存在 我输入文字的日期......请帮帮我......

以下是 ResourceDictionary 的代码:

<Converters:DateConverter x:Key="DateConverter"></Converters:DateConverter>
<Converters:DayBorderColorConverter x:Key="DayBorderColorConverter"></Converters:DayBorderColorConverter>

    <Style TargetType="{x:Type Jarloo:Calendar}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Jarloo:Calendar}">

                <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">

                    <DockPanel>
                        <TextBlock Text="{Binding Date}" />

                        <Grid Height="30" DockPanel.Dock="Top">

                        </Grid>

                        <ItemsControl ItemsSource="{Binding DayNames}" DockPanel.Dock="Top">                              
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock TextAlignment="Center" Text="{Binding}">
                                        <TextBlock.Background>
                                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                <GradientStop Color="#FF171717" Offset="0"/>
                                                <GradientStop Color="#FF040404" Offset="1"/>
                                            </LinearGradientBrush>
                                        </TextBlock.Background>
                                    </TextBlock>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <UniformGrid Rows="1" Columns="7" />
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                        </ItemsControl>

                        <ItemsControl ItemsSource="{Binding Days}">                               
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>                                        
                                    <!--Box-->

                                    <Border BorderBrush="Pink" BorderThickness="0.5" Padding="0">
                                        <Border Name="InnerBorder" BorderBrush="{Binding Path=Notes, Converter={StaticResource DayBorderColorConverter}}" BorderThickness="2">                                                

                                            <Border.Style>
                                                <Style TargetType="{x:Type Border}">
                                                    <Style.Triggers>
                                                        <!--Current Day-->
                                                        <DataTrigger Binding="{Binding IsToday}" Value="true">
                                                            <Setter Property="Border.Background">
                                                                <Setter.Value>
                                                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                                        <GradientStop Color="Black" Offset="0"/>
                                                                        <GradientStop Color="Black" Offset="1"/>
                                                                    </LinearGradientBrush>
                                                                </Setter.Value>
                                                            </Setter>
                                                        </DataTrigger>
                                                    </Style.Triggers>
                                                </Style>
                                            </Border.Style>

                                            <DockPanel>
                                                <!--Day Number-->
                                                <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" FlowDirection="RightToLeft">
                                                    <TextBlock TextAlignment="Right" Text="{Binding Date, Converter={StaticResource DateConverter}, ConverterParameter=DAY}" FontSize="14" Margin="5,5,5,5" >
                                                        <TextBlock.Style>
                                                            <Style TargetType="{x:Type TextBlock}">
                                                                <Style.Triggers>
                                                                    <DataTrigger Binding="{Binding IsTargetMonth}" Value="false">
                                                                        <Setter Property="TextBlock.Foreground" Value="Gray"></Setter>
                                                                    </DataTrigger>
                                                                </Style.Triggers>
                                                            </Style>
                                                        </TextBlock.Style>
                                                    </TextBlock>                                                                                                      
                                                </StackPanel>

                                                <TextBox Name="InputText" IsEnabled="{Binding IsEnabled}" Text="{Binding Notes, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AcceptsReturn="True" TextWrapping="Wrap" BorderThickness="0" ScrollViewer.VerticalScrollBarVisibility="Auto" Background="{x:Null}" Foreground="White" />

                                            </DockPanel>
                                        </Border>
                                    </Border>

                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <UniformGrid Rows="6" Columns="7" />
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                        </ItemsControl>
                    </DockPanel>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

MainWindow

的代码
        List<string> months = new List<string> { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
        cboMonth.ItemsSource = months;

        for (int i = 0; i < 3; i++)
        {
            cboYear.Items.Add(DateTime.Today.AddYears(i).Year);
        }

        cboMonth.SelectedItem = months.FirstOrDefault(w => w == DateTime.Today.ToString("MMMM"));
        cboYear.SelectedItem = DateTime.Today.Year;

        cboMonth.SelectionChanged += (o, e) => RefreshCalendar();
        cboYear.SelectionChanged += (o, e) => RefreshCalendar();


    }

    private void RefreshCalendar()
    {
        if (cboYear.SelectedItem == null) return;
        if (cboMonth.SelectedItem == null) return;

        int year = (int)cboYear.SelectedItem;

        int month = cboMonth.SelectedIndex + 1;

        DateTime targetDate = new DateTime(year, month, 1);

        Calendar.BuildCalendar(targetDate);

    }

    private void Calendar_DayChanged(object sender, DayChangedEventArgs e)
    {
        //save the text edits to persistant storage

    }

0 个答案:

没有答案