Q006. Canvas に配置したコントロールの Anchor を右下で設定したいんですが・・・

A.以下のように Canvas.Right、Canvas.Bottom からの距離を設定します。なお Canvas.Top・Canvas.Left・Canvas.Right・Canvas.Bottom の全てを設定すると Top・Left が優先されるようです。


<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="200" Width="300">
    <Canvas>
        <Button Width="100" Height="30" Canvas.Left="20" Canvas.Top="20" />
        <Button Width="100" Height="30" Canvas.Left="20" Canvas.Bottom="20" />
        <Button Width="100" Height="30" Canvas.Right="20" Canvas.Top="20" />
        <Button Width="100" Height="30" Canvas.Right="20" Canvas.Bottom="20" />
        <Button Width="50" Height="30" 
                Canvas.Left="20" Canvas.Top="20" Canvas.Right="20" Canvas.Bottom="20" />
    </Canvas>
</Window>

#2011/01/26 訂正した。


WPF FAQ の目次に戻る