根据内容调整窗口大小

时间:2018-02-27 15:31:06

标签: c# wpf size autoresize

我尝试过不同的事情,但没有成功

我必须相对于动态的瓷砖数量(MahApps.Metro)调整窗口大小,但只有高度,一旦高度超过我的屏幕,我就会放入一个scroolbar

在我的窗口中我暂时拥有:

<Controls:MetroWindow x:Class="EpiTUILE.MainWindow"
                  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                  xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
Title="EpiTUILE" Height="270" Width="400" ShowMaxRestoreButton="False" ShowCloseButton="False" 
Top="0" Loaded="MetroWindow_Loaded" Icon="Alerte.png" Closing="MetroWindow_Closing" 
MouseMove="MetroWindow_MouseMove" ResizeMode="CanMinimize" MouseEnter="MetroWindow_MouseEnter" 
StateChanged="MetroWindow_StateChanged" WindowStyle="None" UseLayoutRounding="True"
AllowsTransparency="True" Background="Transparent" WindowState="Minimized">

<Window.Resources>
    <Style x:Key="TileStyle" TargetType="Controls:Tile">
        <EventSetter Event="PreviewMouseDown" Handler="OnTileClick" />
        <Setter Property="Width" Value="380" />
        <Setter Property="Height" Value="70" />
        <Setter Property="TitleFontSize" Value="10" />
    </Style>
</Window.Resources>
<Grid Height="Auto">
    <ScrollViewer x:Name="MyScrollViewer" VerticalScrollBarVisibility="Auto" Grid.Row="1" Width="Auto" Height="Auto" Grid.ColumnSpan="2" ScrollViewer.FlowDirection="LeftToRight" >
        <WrapPanel Name="PanelTile" Orientation="Vertical" HorizontalAlignment="Center" Height="Auto" >
        </WrapPanel>
    </ScrollViewer>
</Grid>

然后我在后面的代码中构建我的tile:

PanelTile.Children.Clear();
for (int i = 0; i < _nbrTile; i++)
{
    Tile _tile = new Tile();
    _tile.HorizontalTitleAlignment = HorizontalAlignment.Right;
    _tile.Title = i.ToString();
    _tile.Style = this.FindResource("TileStyle") as Style;
    _tile.Content = "Type Alerte " + i;

    PanelTile.Children.Add(_tile);
}

0 个答案:

没有答案