代码之家  ›  专栏  ›  技术社区  ›  bcm

画布内Silverlight中的动态剪裁宽度

  •  2
  • bcm  · 技术社区  · 14 年前

    为什么这会引发错误,我如何修复。。。我需要设置剪辑矩形为动态。

        <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" />         
    
    3 回复  |  直到 14 年前
        1
  •  2
  •   onmyway133    12 年前

    你还可以用 RectangleGeometry 作为剪裁区域。只需订阅 Loaded 事件,并在此创建一个新的 矩形几何

    void control_Loaded(object sender, RoutedEventArgs e)
            {
                LayoutRoot.DataContext = this;
    
                Rect rect = new Rect(0, 0, yourWidth, yourHeight);
                RectangleGeometry reo = new RectangleGeometry();
                reo.Rect = rect;
                this.canvas.Clip = reo;
            }
    

    此外,不透明度和剪辑特性设置由 如果在动画对象上使用剪辑,则将传递这些操作 到UI线程。这意味着即使剪辑区域是 矩形,但使用路径几何体进行操作 如果可能,用于剪切路径的矩形几何体。

        2
  •  1
  •   bcm    14 年前

    最终解决方案。。。。在多次咒骂和咒骂之后。如果一切都像CSS(overflow-bloody-hidden-property)中那样严格。

    <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>
    

    后端:

    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;
            }
    
        3
  •  0
  •   Denis    14 年前

    推荐文章