How do i bind the Y-coordinates to a slider and the width to a combobox so when u change the slider it looks like its crawling down the left side.
<Window x:Class="Grafik.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.ColumnDefinitions>
<ColumnDefinition Width="80*"/>
<ColumnDefinition Width="30*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="1" Text="Y-Position des Objekts"/>
<Slider Name="position" Minimum="0" Maximum="500" Canvas.Left="20" Grid.Column="1"/>
<ComboBox x:Name="breite" Grid.Column="1" HorizontalAlignment="Left" Margin="5,40,0,0" VerticalAlignment="Top" Width="136">
<ComboBoxItem >15</ComboBoxItem>
<ComboBoxItem >30</ComboBoxItem>
<ComboBoxItem >45</ComboBoxItem>
<ComboBoxItem >60</ComboBoxItem>
</ComboBox>
<Canvas>
<Rectangle Fill="Red" Width="10" Height="10" Canvas.Top="{Binding ElementName=position, Path=Value}"/>
</Canvas>
</Grid>
The binding to the slider's value works for me when I use your code.
You can bind directly to the combobox' value if you put real numbers in there. Otherwise you have to use appropriate converters.
<Window
...
xmlns:system="clr-namespace:System;assembly=mscorlib"
>
<ComboBox ...>
<system:Double>15</system:Double>
...
</ComboBox>
<Rectangle ... Width={Binding SelectedItem ElementName=breite}/>
You might want to preselect a width with:
<ComboBox ... SelectedIndex="0">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.