开发者

WPF (VS2010/.NET4.0) Create a re-usable form layout

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:N开发者_运维知识库ame="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>
  1. 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.
  2. How to have this code in a DLL so that I could re-use it.

Thanks!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜