0

我在使弹出通知面板仅占用其内部控件所需的空间时遇到问题。

我有什么:

 <Grid>
    <DockPanel Panel.ZIndex="1111" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Stretch" Visibility="{Binding MessageVisibility}">
        <Button Visibility="Collapsed" Name="clickButton" Command="{Binding Path=CloseMessage}"/>
        <Border Background="LightGray" CornerRadius="20" MouseDown="Border_MouseDown" BorderThickness="8" BorderBrush="CadetBlue">
            <Grid VerticalAlignment="Center" HorizontalAlignment="Center" Margin="20px">
                <ItemsControl Grid.Column="0" Grid.Row="0" ItemsSource="{Binding Messages}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <TextBlock TextBlock.TextAlignment="Center" Text="{Binding FallbackValue='Message'}"/>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>

                </ItemsControl>

            </Grid>
        </Border>
    </DockPanel>
    <DockPanel  Panel.ZIndex="0">
...
    </DockPanel>
</Grid>

我试图让第一个 DockPanel 只占用 ItemsControl 所需的空间。它似乎占据了整个空间。设置宽度/高度将使其保持在中心,但不会让它增长。

4

2 回答 2

0

从 DockPanel 更改为 Stackpanel 并设置水平/垂直对齐中心有效。

于 2013-02-07T16:49:22.137 回答
0

以下修改后的代码可能会有所帮助并解决您的专业问题

<Grid>
           <Grid.RowDefinitions>            
                <RowDefinition/>            
                <RowDefinition/>            
            </Grid.RowDefinitions> 
       <Grid.ColumnDefinitions>          
             <ColumnDefinitions/>
       </Grid.ColumnDefinitions>          

    <DockPanel Panel.ZIndex="1111" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Stretch" Visibility="{Binding MessageVisibility}">
        <Button Visibility="Collapsed" Name="clickButton" Command="{Binding Path=CloseMessage}"/>
        <Border Background="LightGray" CornerRadius="20" MouseDown="Border_MouseDown" BorderThickness="8" BorderBrush="CadetBlue">
            <Grid VerticalAlignment="Center" HorizontalAlignment="Center" Margin="20px">
                <ItemsControl Grid.Column="0" Grid.Row="0" ItemsSource="{Binding Messages}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <TextBlock TextBlock.TextAlignment="Center" Text="{Binding FallbackValue='Message'}"/>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>

                </ItemsControl>

            </Grid>
        </Border>
    </DockPanel>
    <DockPanel  Panel.ZIndex="0" Grid.Column="0" Grid.Row="1">
...
    </DockPanel>
</Grid>
于 2013-02-07T16:54:55.767 回答