Click here to Skip to main content
15,887,746 members
Home / Discussions / WPF
   

WPF

 
QuestionProblems converting color image to grayscale [modified] Pin
Lenquist26-Sep-10 1:46
Lenquist26-Sep-10 1:46 
AnswerRe: Problems converting color image to grayscale Pin
Abhinav S26-Sep-10 7:23
Abhinav S26-Sep-10 7:23 
GeneralRe: Problems converting color image to grayscale Pin
Lenquist26-Sep-10 8:55
Lenquist26-Sep-10 8:55 
AnswerRe: Problems converting color image to grayscale Pin
Paul Daniel Ruston27-Sep-10 13:59
Paul Daniel Ruston27-Sep-10 13:59 
GeneralRe: Problems converting color image to grayscale Pin
Lenquist27-Sep-10 23:31
Lenquist27-Sep-10 23:31 
QuestionAnimating Object along PathGeometry + transformation Pin
DTh197823-Sep-10 16:04
DTh197823-Sep-10 16:04 
QuestionEfficient WPF drawing code Pin
astibich223-Sep-10 12:17
astibich223-Sep-10 12:17 
QuestionUnable to set focus to datepicker using attached property in wpf Pin
dashingsidds23-Sep-10 1:07
dashingsidds23-Sep-10 1:07 
Hi Experts,

I have a custom datepicker with me and i am trying to set focus to this using attached property. I have the toolkit version 3.5.50211.1 which was released on Feb 2010. The focus is working fine when i do DatePicker.Focus(); in my code. My custom datepicker code is as follows:

-- My DatePicker

using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Windows.Controls;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.ComponentModel;
using System.Windows.Controls.Primitives;

namespace Guardian.PAS.PASFramework.UI.WPF
{
    public class PASDatePicker : DatePicker
    {
        #region Attached Property

        /// <summary>
        /// Get of IsFocus Property.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool GetIsFocus(DependencyObject obj)
        {
            return (bool)obj.GetValue(IsFocusProperty);
        }

        /// <summary>
        /// Set of IsFocus Property.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="value"></param>
        public static void SetIsFocus(DependencyObject obj, bool value)
        {
            obj.SetValue(IsFocusProperty, value);
        }


        public static readonly DependencyProperty IsFocusProperty =
                DependencyProperty.RegisterAttached(
                 "IsFocus", typeof(bool), typeof(PASDatePicker),
                 new UIPropertyMetadata(false, OnIsFocusPropertyChanged));

        /// <summary>
        /// Property change event of IsFocused.
        /// </summary>
        /// <param name="d"></param>
        /// <param name="e"></param>
        private static void OnIsFocusPropertyChanged(DependencyObject d,
                DependencyPropertyChangedEventArgs e)
        {
            var uie = (UIElement)d;
            if ((bool)e.NewValue)
            {
                // Don't care about false values. 
                (uie as PASDatePicker).Focus();
            }
        }
        #endregion
    }
}



I am using this datepicker in my code and trying to set focus using the Isfocus attached property defined above.

-- test form xaml

<Window x:Class="Guardian.PAS.BARSLibrary.Test.frmPASDatePickerTest"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="frmPASDatePickerTest" Height="300" Width="300"
    xmlns:my="clr-namespace:Guardian.PAS.PASFramework.UI.WPF;assembly=Guardian.PAS.PASFramework.UI.WPF">
    <Grid>
        <my:PASDatePicker Name="dtpDate" Height="25" Margin="64,40,64,0" VerticalAlignment="Top"
        my:PASDatePicker.IsFocus ="{Binding GoviddateissuedFocused}" />
        <Button Height="23" Margin="64,90,139,0" Name="button1" VerticalAlignment="Top" Click="button1_Click">change</Button>
    </Grid>
</Window>


-- Test form xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Reflection;
using Microsoft.Windows.Controls;
using System.Configuration;
using System.Data;
using System.Collections;
using System.ComponentModel;

namespace Guardian.PAS.BARSLibrary.Test
{
    /// <summary>
    /// Interaction logic for frmPASDatePickerTest.xaml
    /// </summary>
    public partial class frmPASDatePickerTest : Window, INotifyPropertyChanged
    {
        public frmPASDatePickerTest()
        {
            InitializeComponent();

            dtpDate.Focus();
        }

        private bool _goviddateissuedFocused = false;
        /// <summary>
        /// Get/Set for GoviddateissuedFocused property.
        /// </summary>
        public bool GoviddateissuedFocused
        {
            get { return _goviddateissuedFocused; }
            set
            {
                if (_goviddateissuedFocused != value)
                {
                    _goviddateissuedFocused = value;
                    RaisePropertyChanged("GoviddateissuedFocused");
                }
            }
        }

        #region PropertyChanged Block
        /// <summary>
        /// EventHandler for Property Change
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Raises event on Property Change
        /// </summary>
        /// <param name="property"></param>
        private void RaisePropertyChanged(string property)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }
        #endregion

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            GoviddateissuedFocused = true;
        }
    }
}


Now when i click on change button the datepicker does not get the focus.

Please help!
Thanks in advance!

Regards,

Samar

modified on Thursday, September 23, 2010 8:02 AM

AnswerRe: Unable to set focus to datepicker using attached property in wpf Pin
PumbaPumba27-Sep-10 20:02
PumbaPumba27-Sep-10 20:02 
QuestionCustom control resets font properties set through Xaml Pin
WebMaster22-Sep-10 21:36
WebMaster22-Sep-10 21:36 
AnswerRe: Custom control resets font properties set through Xaml Pin
PumbaPumba27-Sep-10 17:44
PumbaPumba27-Sep-10 17:44 
QuestionDatagrid Pin
Saksida Bojan22-Sep-10 0:16
Saksida Bojan22-Sep-10 0:16 
AnswerRe: Datagrid Pin
Abhinav S22-Sep-10 4:06
Abhinav S22-Sep-10 4:06 
GeneralRe: Datagrid Pin
Saksida Bojan22-Sep-10 9:50
Saksida Bojan22-Sep-10 9:50 
AnswerRe: Datagrid Pin
Abhishek Sur22-Sep-10 9:54
professionalAbhishek Sur22-Sep-10 9:54 
GeneralRe: Datagrid [modified] Pin
Saksida Bojan22-Sep-10 10:12
Saksida Bojan22-Sep-10 10:12 
QuestionAnimation of Expander expand / collapse programmatically Pin
tronix0121-Sep-10 20:58
tronix0121-Sep-10 20:58 
AnswerRe: Animation of Expander expand / collapse programmatically Pin
Abhishek Sur22-Sep-10 9:46
professionalAbhishek Sur22-Sep-10 9:46 
GeneralRe: Animation of Expander expand / collapse programmatically Pin
tronix0124-Sep-10 3:54
tronix0124-Sep-10 3:54 
QuestionRoutedCommands Pin
David_ml_G21-Sep-10 5:30
David_ml_G21-Sep-10 5:30 
AnswerRe: RoutedCommands Pin
Abhishek Sur22-Sep-10 9:50
professionalAbhishek Sur22-Sep-10 9:50 
QuestionSilverlight Installation Trick from Batch file Pin
Kunal Chowdhury «IN»20-Sep-10 19:20
professionalKunal Chowdhury «IN»20-Sep-10 19:20 
AnswerRe: Silverlight Installation Trick from Batch file Pin
Pete O'Hanlon20-Sep-10 22:04
mvePete O'Hanlon20-Sep-10 22:04 
GeneralRe: Silverlight Installation Trick from Batch file Pin
Kunal Chowdhury «IN»20-Sep-10 22:22
professionalKunal Chowdhury «IN»20-Sep-10 22:22 
AnswerRe: Silverlight Installation Trick from Batch file Pin
Abhinav S20-Sep-10 22:25
Abhinav S20-Sep-10 22:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.