更改或访问 Silverlight 数据表单编辑模板中的控件
今天我在使用 Silverlight 数据表单控件时遇到了一个有趣的问题。我想更改绑定编辑模板内特定控件的可见性。请参阅下面的 xaml。
<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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许还有另一个答案,但我所做的是为我的数据类创建一个分部类,并在分部中添加一个返回可见性枚举的属性,然后在绑定到控件之前在后面的代码中设置可见性。
在我的实际 XAML 中,我将绑定到控件可见性属性,如下所示:
希望有帮助
干杯
There maybe another answer to this, but what I did was to create a partial class for my data class and in the partial I added a property that returns the Visibility enum, then set the visibilty in the code behind before binding to the control.
In my actual XAML I would bind to the controls Visibility Property something like this:
Hope that helps
Cheers