WCF/WF - How to set WPF Datepicker readonly property,so that user not able to manipulte

Asked By neha
11-May-10 01:06 AM
How to set WPF Datepicker readonly property,so that user not able to manipulate the selected date from datepicker calendar..???
Any help its urgent..
  Jinal Desai - LIVE replied to neha
11-May-10 04:05 AM
Try SelectionMode=None
  neha replied to Jinal Desai - LIVE
11-May-10 04:13 AM

 

I have created a custom DatePicker which is inherited from DatePicker and added editable dependency property and set it to false in my XAML code
public
static readonly DependencyProperty EditableProperty = DependencyProperty.Register("Editable", typeof(bool),

 

 

typeof(CustomDatePicker), new PropertyMetadata(true));

 

 

public bool Editable

 

{

 

get { return (bool)GetValue(EditableProperty); }

 

 

set { SetValue(EditableProperty, value); }

 

}

 

public override void OnApplyTemplate()

 

{

 

base.OnApplyTemplate();

 

 

var textBox = GetTemplateChild("PART_TextBox") as Microsoft.Windows.Controls.Primitives.DatePickerTextBox;

 

 

var binding = new Binding { Source = this, Path = new PropertyPath(CustomDatePicker.EditableProperty) };

 

textBox.SetBinding(Microsoft.Windows.Controls.Primitives.

DatePickerTextBox.FocusableProperty, binding);

 


}
Create New Account
help
to show the same columns over and over). This may result in long lines of XAML codes if there are a lot of ComboBox controls. It is pretty messy in my the PopupContent dependency property in the default style of the ExtendedComboBox control found in Generic.xaml. I copied the XAML code in my previous article and changed some lines. I only copied the part that check it out. < Window x:Class = "DemoApp.MainWindow" xmlns = "http: / / schemas.microsoft.com / winfx / 2006 / xaml / presentation" xmlns:x = "http: / / schemas.microsoft.com / winfx / 2006 / xaml" xmlns:controls = "clr-namespace:CustomControls;assembly = CustomControls" xmlns:toolkit = "http: / / schemas.microsoft.com / wpf / 2008 control does the same thing as the previous one but as you can see, the XAML code is cleaner. Filtering DataGrid Items Last thing that I want to discuss is that there are two control templates for the ExtendedComboBox control in Generic.xaml. The default control template is what we have been editing so far. The other one setting the Filter property of the ItemCollection object (obtained from DataGrid.Items). To get the TextBox object that contains the text, we need to override the OnApplyTemplate method of the ExtendedComboBoxDataGrid
s say we have some control where its default template contain an Ellipse. On the OnApplyTemplate method, we can get the Ellipse using the GetTemplateChild method. Here is a basic example Ellipse ellipse; static DerivedControl() { DefaultStyleKeyProperty.OverrideMetadata( typeof (DerivedControl), new FrameworkPropertyMetadata( typeof (DerivedControl))); } public override void OnApplyTemplate () { base . OnApplyTemplate (); ellipse = ( DataGrid ) base .GetTemplateChild( "PART_ Ellipse " ); if (ellipse! = null ) { / / Do something with Ellipse } } Related FAQs Set ControlTemplate Programmatically Usually, we use XAML to specify templates for our controls like Button and TextBox. However, there may be some times when we need to do it programmatically or via Control ( 180 Views ) View Michael Detras's FAQs Create New Account keywords: Name, Ellipse, Control, OnApplyTemplate, DataGrid, typeof, override description: When creating a custom control, we usually define a default template
project of type WPF Custom Control Library. This creates two files: CustomControl1.cs and Generic.xaml. Let’s rename CustomControl1 to TimePicker. The TimePicker class derives from the Control class and the control. This is necessary to find the default style for the control. The Generic.xaml file, which is under the Themes folder, is important. This is where the .NET runtime a folder for each control, make sure you merge your resource dictionaries in the Generic.xaml file (or another file depending on the theme). The following shows the contents of the Generic.xaml file. < ResourceDictionary xmlns = "http: / / schemas.microsoft.com / winfx / 2006 / xaml / presentation" xmlns : x = "http: / / schemas.microsoft.com / winfx / 2006 xaml" xmlns : local = "clr-namespace:CustomControlsLib"> < Style TargetType = "{ x : Type local : TimePicker }"> < Setter Property = "Template"> < Setter a Border with default properties. We have to specify a different template in the Generic.xaml file. Most of the time, a control expects the template to have certain kinds of the controls that will make up our TimePicker control. I think there should be three TextBox controls that correspond to the hour, minute and second components. I’ll use the 24
WPF Restrict pasting text in a textbox Use the DataObject's Pasting handler to avoid pasting text into a textbox XAML: <TextBox x:Name = "PasteRestrictedTextBox" DataObject.Pasting = "PasteRestrictedTextBox_Pasting" / > CODE: private void PasteRestrictedTextBox_Pasting(object sender, DataObjectPastingEventArgs e) { e CancelCommand(); } Related FAQs WPF Restrict copying text in a textbox Use the DataObject's Copying handler to avoid copying text from a textbox WPF Restrict pasting text in a textbox ( 185 Views ) View [)ia6l0 iii's FAQs Create New Account keywords: DataObjectPastingEventArgs, WPF, restrict, pasting text, textblock, textbox, DataObject, Pasting, Paste, handler description: Use the DataObject's Pasting handler to avoid pasting text