Changing or accessing a control in a Silverlight Data Form Edit Template
Posted
by Aim Kai
on Stack Overflow
See other posts from Stack Overflow
or by Aim Kai
Published on 2010-04-14T15:52:31Z
Indexed on
2010/04/14
16:03 UTC
Read the original article
Hit count: 1154
I came across an interesting issue today when playing around with the Silverlight Data Form control. I wanted to change the visibility of a particular control inside the bound edit template.. see xaml below.
<df:DataForm x:Name="NoteFormEdit" ItemsSource="{Binding Mode=OneWay}" AutoGenerateFields="True"
AutoEdit="True" AutoCommit="False"
CommitButtonContent="Save"
CancelButtonContent="Cancel"
CommandButtonsVisibility="Commit"
LabelPosition="Top" ScrollViewer.VerticalScrollBarVisibility="Disabled"
EditEnded="NoteForm_EditEnded">
<df:DataForm.EditTemplate>
<DataTemplate>
<StackPanel>
<df:DataField>
<TextBox Text="{Binding Title, Mode=TwoWay}"/>
</df:DataField>
<df:DataField>
<TextBox Text="{Binding Description, Mode=TwoWay}" AcceptsReturn="True" HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto" Height="" TextWrapping="Wrap" SizeChanged="TextBox_SizeChanged"/>
</df:DataField>
<df:DataField>
<TextBlock Text="{Binding Username}" x:Name="tbUsername"/>
</df:DataField>
<df:DataField>
<TextBlock Text="{Binding DateCreated, Converter={StaticResource DateConverter}}" x:Name="tbDateCreated"/>
</df:DataField>
</StackPanel>
</DataTemplate>
</df:DataForm.EditTemplate>
</df:DataForm>
I wanted to depending on how the container of this data form was accessed to disable or hide the last two data fields. I did a work around which had two data forms but this is a bit excessive! Does anyone know how to access these controls inside the edit template?
© Stack Overflow or respective owner