Skip to main content

I am using Visual COBOL with WPF, and I would like to format the DatePicker to just show the Month and Year when entering and displaying data on this field. 

What would the code be for Visual COBOL to do that??

I am using Visual COBOL with WPF, and I would like to format the DatePicker to just show the Month and Year when entering and displaying data on this field. 

What would the code be for Visual COBOL to do that??

There may be an easier way to do this but I found an example that changes the underlying template format using the xaml code.

<DatePicker SelectedDate="{x:Static sys:DateTime.Now}">
   <DatePicker.Resources>
      <Style TargetType="DatePickerTextBox">
         <Setter Property="Control.Template">
            <Setter.Value>
               <ControlTemplate>
                  <TextBox x:Name="PART_TextBox"
                     Text="{Binding Path=SelectedDate, StringFormat={}{0:MM/yyyy}, 
                     RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}}" />
               </ControlTemplate>
            </Setter.Value>
         </Setter>
      </Style>
   </DatePicker.Resources>
</DatePicker>


There may be an easier way to do this but I found an example that changes the underlying template format using the xaml code.

<DatePicker SelectedDate="{x:Static sys:DateTime.Now}">
   <DatePicker.Resources>
      <Style TargetType="DatePickerTextBox">
         <Setter Property="Control.Template">
            <Setter.Value>
               <ControlTemplate>
                  <TextBox x:Name="PART_TextBox"
                     Text="{Binding Path=SelectedDate, StringFormat={}{0:MM/yyyy}, 
                     RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}}" />
               </ControlTemplate>
            </Setter.Value>
         </Setter>
      </Style>
   </DatePicker.Resources>
</DatePicker>

Chris - that worked wonderfully!! Thanks so much for your help!!