views:

36

answers:

2

Hello,

I am probably over-doing a very simple problem, but this is what I have a the moment:

I have several buttons and a listbox of items in which the user can select and interact with. My application also moves those elements in accordance to the application width/height, such as follows:

listBox1.Margin = new Thickness(this.ActualWidth * 0.84, this.ActualHeight * 0.3, 0, 0);

I am able to select the items within the listbox and click on buttons appropriately while in windowed mode, but as I begin to stretch the application larger, I try to click on the items, and I cannot do so.. is this because I also need to update their hit-detection rectangles as well? Or perhaps am I moving the items incorrectly? I am at a loss.. any information would be very helpful at this point...thanks!

A: 

Not sure why you can't click the items anymore after resizing. That can have a lot of reasons. Obviously you want to have proportional margins around the ListBox. You would normally do that with a Grid:

<Grid>
  <Grid.ColumnDefinitions>
     <ColumnDefinition Width="0.83*"/>
     <ColumnDefinition/>
  </Grid.ColumnDefinitions>
  <Grid.RowDefinitions>
     <RowDefinition Height="0.3*"/>
     <RowDefinition/>
  </Grid.RowDefinitions>
  <ListBox x:Name="listBox1" Grid.Column="1" Grid.Row="1"/>
</Grid>
bitbonk
A: 

I write this XAML:

<Window x:Class="StackOverflow_MovingProblem.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">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <ListBox Name="listbox1" ItemsSource="{Binding Path=list}" />
        <StackPanel Grid.Row="1" Orientation="Horizontal">
            <Button Content="button1" />
            <Button Content="button2" />
            <Button Content="button3" />
        </StackPanel>
    </Grid>
</Window>

with this code-behind:

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            DataContext = this;

            SizeChanged += new SizeChangedEventHandler(MainWindow_SizeChanged);

            list = new ObservableCollection<string>();
            list.Add("item1");
            list.Add("item2");
            list.Add("item3");
        }

        public ObservableCollection<string> list { get; set; }

        void MainWindow_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            listbox1.Margin = new Thickness(this.ActualWidth * 0.84,
                                            this.ActualHeight * 0.3, 0, 0);
        }
    }

but I'm not able to reproduce your problem. Check my code if there is something different with your code and tell me what, so I can give you some advices. Thank you

Maurizio Reginelli
Hm, the code looks right.. let me go ahead and compare and test some more.. I'll get back with you..
Kyle
I tried it using your settings, but try these: new Thickness(this.ActualWidth * 0.411, this.ActualHeight * 0.435, 0, 0);It works fine when I use your settings, but under these ones perhaps you will see the problem. Oh, and the height and width for the app window for me is: height=768, width=1024
Kyle