WPF (VS2010/.NET4.0) 创建可重用的表单布局
简而言之,我想要实现的是拥有一个可重用的 DLL,它可能具有类似向导的形式。然后我可以简单地设置内容。我花了相当多的时间进行搜索,但我仍然不确定最好的方法是什么。我也看过这篇文章。
我在 XAML 代码中得到了以下结构:
<Grid x:Name="MainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="30"/>
<RowDefinition Height="20"/>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
<RowDefinition Height="30"/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="20"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Content="{Binding ScreenTitleText}" />
<Label x:Name="ContentTitle" Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="2" Content="{Binding ContentTitleText}" />
<Button x:Name="BackButton" Grid.Row="5" Grid.Column="1" Content="Back" />
<Button x:Name="NextButton" Grid.Row="5" Grid.Column="3" Content="Next" />
<ScrollViewer Grid.Row="4" Grid.Column="2" Content="{Binding InnerContent}" x:Name="InnerControl"/>
</Grid>
- 我想知道如何制作它,以便我可以设置 row=4 和 column=2 上的内容,例如一组单选按钮。
- 如何将此代码放入 DLL 中,以便我可以重复使用它。
谢谢!
In a nutshell what Im trying to achieve is to have a re-usable DLL which will potentially have a wizard like form. I could then simply set the content. Ive spent quite a bit of time searching but Im still not sure whats the best way to go. Ive had a look at this article as well.
Ive got the following structure in the XAML code:
<Grid x:Name="MainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="30"/>
<RowDefinition Height="20"/>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
<RowDefinition Height="30"/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="20"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Content="{Binding ScreenTitleText}" />
<Label x:Name="ContentTitle" Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="2" Content="{Binding ContentTitleText}" />
<Button x:Name="BackButton" Grid.Row="5" Grid.Column="1" Content="Back" />
<Button x:Name="NextButton" Grid.Row="5" Grid.Column="3" Content="Next" />
<ScrollViewer Grid.Row="4" Grid.Column="2" Content="{Binding InnerContent}" x:Name="InnerControl"/>
</Grid>
- Id like to know how to make it so that I could set the content on row=4 and column=2 to say for example a set of radio buttons.
- How to have this code in a DLL so that I could re-use it.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其创建为类库或 WPF 用户控件库中的 WPF 用户控件。然后,将 ContentControls 放在您想要动态内容的位置。您可以为每个 ContentControl 公开 DataTemplate 属性。 ContentControls 可以将其模板绑定到 DataTemplate,您应该可以开始了。
Create this as a WPF User Control in a Class Library or a WPF User Control Library. Then, put ContentControls where you want the dynamic stuff to go. You can expose DataTemplate properties for each of those ContentControls. The ContentControls can bind their Template to a DataTemplate and you should be good to go.