Note that there are some explanatory texts on larger screens.

plurals
  1. PODataTemplateSelector and update binding manually
    primarykey
    data
    text
    <p>I am using a DataTemplateSelector to swap input method for user based on whether he wants to enter text or pick a date value. Which means the selector switches between a TextBox and a DatePicker. Each control must use explicit way to update binding source. To sum up the user could pick a date or he could enter a text and once he is done he may click on apply button to update sources. Though only apply button updates the souce and not on focus lost.</p> <p>The owner control of the DataTemplateSelector is a custom ContentControl called InputControl which is futhermore part of a UserControl.</p> <p>Here is a small piece of pseudocode just to visualize things better:</p> <pre><code>public class InputControl : ContentControl { //// this method shall be executed once user clicks on apply button //// inside this method the source of binding shall be updated no matter what input method used chose public void Update() { } } </code></pre> <p>Xaml looks kinda like this:</p> <pre><code>&lt;UserControl&gt; &lt;UserControl.Resources&gt; &lt;DataTemplate x:key="text"&gt; &lt;TextBox Text="{Binding Mode=TwoWay, Path=., UpdateSourceTrigger=Explicit}"/&gt; &lt;/DataTemplate&gt; &lt;DataTemplate x:key="date"&gt; &lt;DatePicker DateValue="{Binding Mode=TwoWay, Path=., UpdateSourceTrigger=Explicit}"/&gt; &lt;/DataTemplate&gt; &lt;MyDataTemplateSelector x:key="myDataTemplateSelector" TextTemplate="{StaticResource text}" DateTemplate="{StaticResource date}"&gt; &lt;/MyDataTemplateSelector&gt; &lt;/UserControl.Resources&gt; &lt;Inputcontrol Content="{Binding Path=., Mode=TwoWay}" ContentTemplateSelector="{StaticResource myDataTemplateSelector}" /&gt; &lt;/UserControl&gt; </code></pre> <p>The selector looks like this</p> <pre><code>Public class MyDataTemplateSelector : DataTemplateSelector { Public DataTemplate TextTemplate { get; set;} Public DataTemplate DateTemplate { get; set;} Public DataTDemplate Select(.....) { .... } } </code></pre> <p>Now the problem is how do I update the binding source from InputControl no matter what control is selected inside the template? If you read the comments above the method InputControl.Update() you will understand better what I mean with user updating source no matter what template.</p> <p>If its TextBox selected the user shall be able to just call InputControl.Update() and it will update textbox binding source. If its DatePicker the user shall be able to do the same which is only to call InputControl.Update(). The source will get updated and Inputcontrol.Update() is a central point to trigger updating process no matter what control.</p> <p>To sum up the method Update() is pretty central and updates the binding source no matter if its TextBox or DatePicker.</p> <p>How do I do that?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload