Announcement

Collapse
No announcement yet.

WPF: Control-Position übernehmen

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • WPF: Control-Position übernehmen

    Hallo!

    Ich möchte Button A zur Laufzeit genau an die Position von Button B (gleiches Fenster) setzen.

    Gibt es eine Möglichkeit, das per VB-Code zu machen?

    Gruß

    Kai

  • #2
    Hallo,

    setzt einfach die Position von A zu der von B. Je nach Container-Control ist das entweder die Margin, die X/Y-Koordinaten.


    mfG Gü
    "Any fool can write code that a computer can understand. Good programmers write code that humans can understand". - Martin Fowler

    Comment


    • #3
      Sorry, hätte ich natürlich erwähnen müssen: In diesem Fall ist es ein Grid und die beiden Buttons befinden sich in verschiedenen Zellen des gleichen Grids.

      Ich weiß nicht, wie ich Button A in eine andere Zelle bekomme, also z.B. Grid.Row per VB-Code verändere. Gestern gegooglet, eben wieder: ich finde nichts :-(
      Zuletzt editiert von gfoidl; 19.11.2010, 14:41. Reason: Full-Quote entfernt

      Comment


      • #4
        Hallo,

        guck mal.

        [highlight=xml]
        <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="350" Width="525">

        <Window.Resources>
        <Style TargetType="Button">
        <Setter Property="Width" Value="80" />
        <Setter Property="Height" Value="23" />
        </Style>
        </Window.Resources>

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

        <Button x:Name="btnA"
        Grid.Row="0"
        Content="A" />

        <Button x:Name="btnB"
        Grid.Row="1"
        Content="B" />

        <Button x:Name="btnSetAtoB"
        Grid.Row="2"
        Content="Set A to B"
        Click="btnSetAtoB_Click" />
        </Grid>
        </Window>
        [/highlight]

        [highlight=c#]
        public partial class MainWindow : Window
        {
        public MainWindow()
        {
        InitializeComponent();
        }

        private void btnSetAtoB_Click(object sender, RoutedEventArgs e)
        {
        Grid.SetRow(btnA, 1);
        }
        }
        [/highlight]

        Sonst auch LayoutTransform, Margin, etc


        mfG Gü
        "Any fool can write code that a computer can understand. Good programmers write code that humans can understand". - Martin Fowler

        Comment

        Working...
        X