Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
805
How to get the value inside control template
posted

Hi,

       I have a field in XamDataGrid, that holds another control say TextBox, I am setting that cell as active, but not sure how to set the focus inside the textbox. How to get the textbox that is inside the controltemplate? Thanks

E.g.,

<Style x:Key="MaskedTextBox" TargetType="{x:Type DataPresenter:CellValuePresenter}">
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="{x:Type DataPresenter:CellValuePresenter}">
                <Controls:TextboxEditor x:Name="txteditor" BorderBrush="{x:Null}" Background="Transparent" TaxCode="{Binding Path=DataItem.Age, Mode=TwoWay}"  IsReadOnly ="{Binding Path=DataItem.IsSystemDefined}"  />
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </Style> 

 

I apply this style, to a field now.

            <DataPresenter:Field Column="2" Row="0" Name="Age" Label="Tax Code">
              <DataPresenter:Field.Settings>
                <DataPresenter:FieldSettings LabelTextWrapping="Wrap" LabelWidth="80" LabelMinWidth="60" CellMinWidth="60" CellWidth="80" AllowEdit ="true" CellValuePresenterStyle="{StaticResource MaskedTextBox}"/>
              </DataPresenter:Field.Settings>
            </DataPresenter:Field>

 

Regards,

Balaji Rajendran - WK CCH

Torrance CA

  • 69686
    posted

    Hello Balaji,

    By re-templating the CellValuePresenter, which uses PART names in its template, you will break the XamDataGrids selection, activation, navigation etc. functionalities. If you want to preserve them and still have a custom control it XamDataGrid's cells, perhaps it would be better to use Andrew Smith's host control (which is an modified value editor). You can check his blog post on this here. This will allow you to preserve all of the lost functionality and be able to start edit mode on these cells.