更改或访问 Silverlight 数据表单编辑模板中的控件

发布于 2024-08-28 20:26:23 字数 1785 浏览 3 评论 0原文

今天我在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自由如风 2024-09-04 20:26:23

也许还有另一个答案,但我所做的是为我的数据类创建一个分部类,并在分部中添加一个返回可见性枚举的属性,然后在绑定到控件之前在后面的代码中设置可见性。

 public partial class MyDataClass
 {
    public Visibility IsVisible { get; set; }

 }

在我的实际 XAML 中,我将绑定到控件可见性属性,如下所示:

   <df:DataField>    
   <TextBlock  Visibility="{Binding  IsVisible }" Text="{Binding DateCreated, Converter={StaticResource DateConverter}}" x:Name="tbDateCreated"/>    

希望有帮助
干杯

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.

 public partial class MyDataClass
 {
    public Visibility IsVisible { get; set; }

 }

In my actual XAML I would bind to the controls Visibility Property something like this:

   <df:DataField>    
   <TextBlock  Visibility="{Binding  IsVisible }" Text="{Binding DateCreated, Converter={StaticResource DateConverter}}" x:Name="tbDateCreated"/>    

Hope that helps
Cheers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文