Changing or accessing a control in a Silverlight Data Form Edit Template
- by Aim Kai
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?