确保控件在multilang界面中保留在其区域中

时间:2012-05-23 21:34:08

标签: c# wpf localization controls

我有一个我试图制作多语言的布局,但随着转换出现了一些障碍。

英文:

enter image description here

德语:

enter image description here

如您所见,复选框在网格中飞来飞去,如何对其进行排序以免与其他控件发生冲突?

由于

使用XAML编辑:

<Grid x:Name="Block" Margin="23,70,24.002,153">
            <Rectangle Fill="#FFDDDDDD" Stroke="#FFD7D7D7" Height="54" VerticalAlignment="Top" RadiusX="2" RadiusY="2"/>
            <Rectangle Fill="#FFE8E8E8" Margin="0,19,0,0" Stroke="#FFD7D7D7"/>
            <Label Height="22" Content="{Binding Source={StaticResource localisation}, Mode=OneWay, Path=.[Language.settings]}" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="10" FontFamily="Myriad Pro" Foreground="#FF585858"/>
            <TextBox MaxLength="2" x:Name="textTimeMin" Margin="175.145,34.336,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" FontFamily="Myriad Pro" Style="{DynamicResource style1Text}" Height="25.2" HorizontalAlignment="Left" Width="30"/>
            <TextBox MaxLength="2" x:Name="textTimeHour" Margin="132.868,34.336,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" HorizontalAlignment="Left" Width="30" FontFamily="Myriad Pro" Style="{DynamicResource style1Text}" Height="25.2"/>
            <Label Content=":" HorizontalAlignment="Left" Margin="162.868,35,0,0" FontSize="11" Foreground="#FF585858" FontFamily="Myriad Pro" VerticalAlignment="Top"/>
            <Label Content="{Binding Source={StaticResource localisation}, Mode=OneWay, Path=.[Language.timeOptions1]}" HorizontalAlignment="Left" Margin="6.148,36.332,0,0" VerticalAlignment="Top" FontSize="11" Foreground="#FF585858" FontFamily="Myriad Pro" Height="23.2"/>
            <Label Content="{Binding Source={StaticResource localisation}, Mode=OneWay, Path=.[Language.timeOptions2]}" HorizontalAlignment="Left" Margin="6.148,67.999,0,52.799" FontSize="11" Foreground="#FF585858" FontFamily="Myriad Pro" Height="23.202"/>
            <Custom:DatePicker x:Name="pickerDate" Margin="134,68.149,188,51.851" d:LayoutOverrides=", Height" FontFamily="Myriad Pro" IsTodayHighlighted="False" Foreground="#FF585858"/>
            <Button x:Name="btnAddTask" Content="{Binding Source={StaticResource localisation}, Mode=OneWay, Path=.[Language.addTask]}" HorizontalAlignment="Left" Margin="8,0,0,8" VerticalAlignment="Bottom" Style="{DynamicResource style1Btn}" Click="btnAddTask_Click" Height="24.65"/>
            <CheckBox x:Name="checkIgnoreDate" Content="{Binding Source={StaticResource localisation}, Mode=OneWay, Path=.[Language.ignoreDate]}" HorizontalAlignment="Right" Margin="0,0,105,55.706" VerticalAlignment="Bottom" Foreground="#FF585858" Background="{x:Null}" Checked="checkIgnoreDate_Checked" Unchecked="checkIgnoreDate_Unchecked" Height="15.96"/>
            <Rectangle x:Name="ignoreDateStrike" Fill="#FF444444" Height="1" Margin="6.148,0,199.32,64" VerticalAlignment="Bottom" Visibility="Collapsed"/>
            <Button x:Name="btnNow" Content="{Binding Source={StaticResource localisation}, Mode=OneWay, Path=.[Language.now]}" Margin="206.088,34.27,176.585,0" VerticalAlignment="Top" Style="{DynamicResource style1Btn}" Height="25.2" FontSize="9.333" Click="btnNow_Click"/>
        </Grid>

1 个答案:

答案 0 :(得分:1)

根据您的屏幕截图和代码,您可以通过几种不同的方式来解决这个问题。

我建议使用包含三列和三行的网格,其中列是自动调整的。无论你的领域有多长,这都将确保一切顺利排列,并且非常适合。

enter image description here

您的网格代码如下所示:

<Grid x:Name="Block">
<Grid.RowDefinitions>
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
...   
</Grid>

然后,您只需为网格中的每个项目设置适当的行和列,而不是对其边距进行硬编码。

   <Button x:Name="btnAddTask" Grid.Row="1" .... />