0

親ウィンドウで UserControl を適切に塗りつぶしたりサイズ変更したりするのに問題があります。MVVM を使用して WPF アプリケーションを作成しています。他の答えを探しましたが、これを理解できませんでした。

MainWindow.xaml

<Window x:Class="QiXR.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:vm="clr-namespace:QiXR.ViewModel"
    xmlns:vw="clr-namespace:QiXR.View"
    Title="MainWindow">
<Window.Resources>
    <DataTemplate DataType="{x:Type vm:XRTestCaseListViewModel}">
        <vw:XRTestCaseListView/>
    </DataTemplate>

</Window.Resources>
<Grid>
    <ItemsControl ItemsSource="{Binding ViewModels}" />
</Grid>

ユーザーコントロール

<UserControl x:Class="QiXR.View.XRTestCaseListView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         VerticalAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<UserControl.Resources>
    <Style x:Key="DataGridCheckBoxStyle" TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}">
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="HorizontalAlignment" Value="Center"/>
    </Style>
</UserControl.Resources>

<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="160"/>
        <ColumnDefinition Width="160"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="30"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="45"/>
    </Grid.RowDefinitions>

MainWindow でUserControlを起動すると、次のように表示されます 。

UserControl または MainWindow の xaml でこれを行うことは可能ですか? ありがとう

4

2 に答える 2

-1

ウィンドウをコンテンツ (ItemsControl の下のメニューとボタンを含む) のサイズに合わせて、より多くのコンテンツが利用可能な場合にウィンドウを大きくするオプションを使用する場合は、SizeToContent プロパティを設定できます。

<Window x:Class="Project.Window"
    x:Name="userControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="400" MaxHeight="700"
    SizeToContent="Height" WindowStartupLocation="CenterScreen">

</Window>

ウィンドウは、内容に合わせて高さが大きくなります。そこで、MaxHeight プロパティを設定して、ItemsControl にかなりの数の項目がある場合にウィンドウが大きくなりすぎないようにすることもできます。

于 2016-03-17T21:00:01.670 に答える