Click here to Skip to main content
15,891,657 members
Home / Discussions / C#
   

C#

 
Questionsalam Pin
hotthoughtguy25-Mar-09 7:46
hotthoughtguy25-Mar-09 7:46 
AnswerRe: salam Pin
0x3c025-Mar-09 7:48
0x3c025-Mar-09 7:48 
GeneralRe: salam Pin
hotthoughtguy25-Mar-09 8:11
hotthoughtguy25-Mar-09 8:11 
GeneralRe: salam Pin
dan!sh 25-Mar-09 9:10
professional dan!sh 25-Mar-09 9:10 
GeneralRe: salam Pin
0x3c025-Mar-09 9:19
0x3c025-Mar-09 9:19 
AnswerRe: salam Pin
Henry Minute25-Mar-09 11:10
Henry Minute25-Mar-09 11:10 
GeneralRe: salam Pin
hotthoughtguy25-Mar-09 18:57
hotthoughtguy25-Mar-09 18:57 
QuestionBinding issue Pin
hb5213421425-Mar-09 7:43
hb5213421425-Mar-09 7:43 
Assuming that I have the following xaml code:

<UserControl x:Class="Test.DateList"<br />
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br />
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br />
    xmlns:c="clr-namespace:Test"><br />
<DockPanel><br />
  <StackPanel><br />
    <RadioButton Checked="YMD"> Show YMD </RadioButton><br />
    <RadioButton Checked="MDY"> Show MDY </RadioButton><br />
  </StackPanel><br />
  <ListView Name="list"><br />
     <ListView.ItemTemplate><br />
        <DataTemplate><br />
           <TextBlock Text="{Binding Path=Date, Converter=???" /><br />
        </DataTemplate><br />
     </ListView.ItemTemplate><br />
  </ListView><br />
</DockPanel>


and the following class:



[ValueConversion(typeof(DateTime), typeof(String))]<br />
partial class DateList : UserControl, IValueConverter<br />
{<br />
   enum Form { YMD, MDY }<br />
   Form DateForm = YMD;<br />
   public DateList()<br />
   {<br />
       InitializeComponent();<br />
<br />
       // initialize the content of the ListView<br />
       List<DateTime> dates = new List<DateTime>();<br />
       for (int i=0;i<10;i++)<br />
           dates.Add(DateTime.Today + TimeSpan.FromDays(i));<br />
       list.ItemsSource = dates;<br />
   }<br />
  void YMD(object sender, RoutedEventArgs e)<br />
  {<br />
     DateForm = Form.YMD;<br />
     list.InvalidateVisual();<br />
  }<br />
  void MDY(object sender, RoutedEventArgs e)<br />
  {<br />
     DateForm = Form.MDY;<br />
     list.InvalidateVisual();<br />
  }<br />
  public object Convert(object value, Type targetType, object parameter, CultureInfo culture)<br />
  {<br />
      DateTime dt = (DateTime)value;<br />
      DateList dl = parameter as DateList;<br />
      if (dl != null)<br />
      {<br />
        switch (dl.DateForm)<br />
        {<br />
          case Form.YMD: return dt.ToString("yyyy/MM/dd");<br />
          case Form.MDY: return dt.ToString("MMM dd, yyyy");<br />
        }<br />
      }<br />
      return null;<br />
  }<br />
  public Object ConvertBack(object value, Type targetType, object parameter, CultureInfo ci) { return null; }<br />
}


How can I link the converter in the data template to correctly display the dates?

As I've coded the example, my thoughts were to use the ConverterParameter and to pass the reference
to the class, but I don't know how to set this to anythign other than a static value within the xaml file.

Any suggestions would be greatly appreciated.
AnswerRe: Binding issue Pin
Henry Minute25-Mar-09 11:19
Henry Minute25-Mar-09 11:19 
AnswerRe: Binding issue Pin
DaveyM6925-Mar-09 11:28
professionalDaveyM6925-Mar-09 11:28 
Questionurgently required.. pls reply... Pin
Nirmala VijayAseelan25-Mar-09 7:37
Nirmala VijayAseelan25-Mar-09 7:37 
AnswerRe: urgently required.. pls reply... Pin
CPallini25-Mar-09 8:11
mveCPallini25-Mar-09 8:11 
AnswerRe: urgently required.. pls reply... Pin
MumbleB25-Mar-09 8:23
MumbleB25-Mar-09 8:23 
AnswerRe: urgently required.. pls reply... Pin
DaveyM6925-Mar-09 11:29
professionalDaveyM6925-Mar-09 11:29 
AnswerRe: urgently required.. pls reply... Pin
Henry Minute25-Mar-09 14:30
Henry Minute25-Mar-09 14:30 
AnswerRe: urgently required.. pls reply... Pin
King Julien25-Mar-09 19:33
King Julien25-Mar-09 19:33 
GeneralRe: urgently required.. pls reply... Pin
Nirmala VijayAseelan26-Mar-09 7:12
Nirmala VijayAseelan26-Mar-09 7:12 
GeneralRe: urgently required.. pls reply... Pin
King Julien26-Mar-09 19:29
King Julien26-Mar-09 19:29 
QuestionHow to declare/tie a mdigrandchild form to mdiGrandParent form? Pin
Lecutus125-Mar-09 7:04
Lecutus125-Mar-09 7:04 
AnswerRe: How to declare/tie a mdigrandchild form to mdiGrandParent form? Pin
Henry Minute25-Mar-09 11:24
Henry Minute25-Mar-09 11:24 
GeneralRe: How to declare/tie a mdigrandchild form to mdiGrandParent form? Pin
Lecutus126-Mar-09 7:53
Lecutus126-Mar-09 7:53 
GeneralRe: How to declare/tie a mdigrandchild form to mdiGrandParent form? Pin
Henry Minute26-Mar-09 9:07
Henry Minute26-Mar-09 9:07 
QuestionLate Typed List Pin
Adriaan Davel25-Mar-09 7:02
Adriaan Davel25-Mar-09 7:02 
AnswerRe: Late Typed List Pin
Adam Maras25-Mar-09 7:08
Adam Maras25-Mar-09 7:08 
AnswerRe: Late Typed List Pin
Curtis Schlak.25-Mar-09 7:26
Curtis Schlak.25-Mar-09 7:26 

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.