UserControl Dimensionen an Parent binden



  • Guten Abend,

    ich versuche gerade verzweifelt oben genanntes zu bewerkstelligen.
    Zum besseren Verständnis erstmal der Code:

    <UserControl
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/20010"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:ec="http://schemas.microsoft.com/expression/2010/controls" 
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d">
    
    	<Grid x:Name="LayoutRoot">
    		<Grid.RowDefinitions>
    			<RowDefinition Height="0.1*"/>
    			<RowDefinition Height="0.6*"/>
    			<RowDefinition Height="0.1*"/>
    		</Grid.RowDefinitions>
    		<Grid.ColumnDefinitions>
    			<ColumnDefinition Width="0.1*"/>
    			<ColumnDefinition Width="0.6*"/>
    			<ColumnDefinition Width="0.1*"/>
    		</Grid.ColumnDefinitions>
    
    		<Ellipse Grid.Row="1" Grid.Column="1" Name="EllipsePath" Fill="Black" Width="{Binding ActualWidth}" Height="{Binding ActualHeight}"/>
    		<ec:PathListBox>
    			<ec:PathListBox.LayoutPaths>
    				<ec:LayoutPath SourceElement="{Binding ElementName=EllipsePath}" Padding="1.7"/>
    			</ec:PathListBox.LayoutPaths>
                <ec:PathListBox.Resources>
                    <sys:Double x:Key="divisor">2.0</sys:Double>
                </ec:PathListBox.Resources>
    			<ec:PathListBox.Items>
                    <Ellipse x:Name="Ellipse1" Width="{Binding ActualWidth, 
    												   ElementName=LayoutRoot, 
    												   Converter={StaticResource divisionHelper}, 
    												   ConverterParameter={StaticResource divisor}}" 
    											Height="{Binding ActualHeight, 
    													 ElementName=LayoutRoot, 
    													 Converter={StaticResource divisionHelper}, 
    													 ConverterParameter={StaticResource divisor}}" 
    													 Fill="White"/>
    				<!-- weitere 7 Ellipsen mit den leichen Bindings -->
    			</ec:PathListBox.Items>
    		</ec:PathListBox>		
    	</Grid>
    </UserControl>
    

    Der Vollständigkeit halber:

    public class DivisionHelper : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                return (double)value / (double)parameter;
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                throw new NotSupportedException();
            }
        }
    

    Das einzige was ich als Resultat erhalte ist die schwarze "Path-Ellipse" die ich für meine PathListBox verwenden.

    Was mache ich hier falsch? Schon mal vielen Dank vorab, für jede Hilfe.


Anmelden zum Antworten