弹出窗口控件模板

时间:2018-08-29 14:32:17

标签: c# wpf mvvm

我有一个带有ListBox的按钮和弹出窗口。我从ViewModel中获取数据源和按钮命令。我还需要其他一些按钮以及ListBox和其他VM按钮命令的其他来源。如何在没有Ctr + C Ctrl + V的情况下重用此代码?如何为此弹出窗口创建控件/数据模板?

<Window x:Class="WpfApplication2.MainWindow"       
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <StackPanel Margin="10">
        <ToggleButton Content="Districts..." x:Name="DistrictButton"/>
        <Popup IsOpen="{Binding IsChecked, ElementName=DistrictButton}" PlacementTarget="{Binding ElementName=DistrictButton}" StaysOpen="True">
            <Border BorderThickness="1" Background="White" Padding="10">
                <Grid Width="400" Height="300">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <ListBox Grid.ColumnSpan="4" ItemsSource="{Binding FilterModel.Districts}"/>
                    <Button Grid.Row="1" Content="Select all" Margin="0,10,0,0" Command="{Binding SelectAllDistrictsCommand}"/>
                    <Button Grid.Row="1" Grid.Column="2" Content="OK" Margin="0,10,0,0" Command="{Binding OKDistrictsCommand}"/>
                    <Button Grid.Row="1" Grid.Column="3" Content="Cancel" Margin="5,10,0,0" Command="{Binding CancelDistrictsCommand}"/>
                </Grid>
            </Border>
        </Popup>
    </StackPanel>

    <!-- Popup again with another DataSource -->
</Grid>

0 个答案:

没有答案