views:

80

answers:

2

Why does this throw an error and how can I fix... I need to set the clipping rect to be dynamic.

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="42"/>
        <ColumnDefinition x:Name="ListBoxContainer" Width="*"/>
        <ColumnDefinition Width="42"/>
    </Grid.ColumnDefinitions>


    <Canvas>
        <Button x:Name="btnGalleryLeft" 
                Click="btnGalleryLeftClick" 
                Style="{StaticResource GalleryNavigationLeft}"
                Canvas.Left="7"
                Canvas.Top="50" />
    </Canvas>
    <Canvas Grid.Column="1" x:Name="ListboxWrapper">
        <Canvas.Clip>
            <RectangleGeometry>
                <RectangleGeometry.Rect>
                    <Rect X="0" Y="0" 
                          Width="{Binding ElementName=ListBoxContainer, Path=Width}"
                          Height="{Binding ElementName=ListBoxContainer, Path=Height}"/>
                </RectangleGeometry.Rect>
            </RectangleGeometry>
        </Canvas.Clip>
        <ListBox x:Name="ListBox1" 
                 Margin="15, 18, 15, 0"  
                 Style="{StaticResource GalleryListBoxStyle}" 
                 ItemsSource="{Binding DocItemCollection}" 
                 SelectionChanged="ListBox_SelectionChanged" 
                 MouseLeftButtonUp="ListBox_MouseLeftButtonUp" 
                 Canvas.Top="0"
                 Canvas.Left="0"
               />
    </Canvas>
    <Canvas Grid.Column="2">
        <Button x:Name="btnGalleryRight"                     
                Click="btnGalleryRightClick" 
                Style="{StaticResource GalleryNavigationRight}"
                Margin="0, 0, 7, 0"
                Canvas.Top="50" />         
A: 

I think you are over complicating it. Binding to Width/Height of ColumnDefinition not going to work. I'd simply create behavior that would subscribe to SizeChanged event and set clipping based on ActualWidth[Height].

Denis
I'm very new to silverlight.. now how do I do that? Am I still setting the width and height of a clipping rect through the SizeChange event?
Brandon
A: 

Solution finally.... after much cursin and swearing. If only everything was as stright fwd as in CSS (overflow bloody hidden property).

Front-end:

<Canvas Grid.Column="1" x:Name="ListboxWrapper" Background="Black">
            <ScrollViewer Background="Red" 
                          FlowDirection="LeftToRight" 
                          HorizontalScrollBarVisibility="Hidden" 
                          VerticalScrollBarVisibility="Hidden"
                          x:Name="ScrollViewerClipper">                
                <Canvas x:Name="CarouselContainer">
                    <gallery:ImageCarousel x:Name="carousel" />
                </Canvas>
            </ScrollViewer>

Back-end:

public GalleryPanel()
        {
            InitializeComponent();

            LayoutRoot.SizeChanged +=new SizeChangedEventHandler(LayoutRoot_SizeChanged);
        }

        private void LayoutRoot_SizeChanged(object s, SizeChangedEventArgs e)
        {
            ScrollViewerClipper.Width = ListboxWrapper.ActualWidth;
            ScrollViewerClipper.Height = ListboxWrapper.ActualHeight;
        }
Brandon
(Using a scrollviewer as a clipper instead of a clipping rectangle)
Brandon