Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight xaml中多个控件的容器_Silverlight_Xaml_Custom Controls - Fatal编程技术网

Silverlight xaml中多个控件的容器

Silverlight xaml中多个控件的容器,silverlight,xaml,custom-controls,Silverlight,Xaml,Custom Controls,我正在尝试为silverlight应用程序创建一个自定义控件,该控件基本上允许用户在画布上单击和拖动,并在两端绘制一条带有小矩形的线。如何将这三个控件封装到一个自定义控件中。我想做这样的事 <UserControl x:Class="Linecontrol" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx

我正在尝试为silverlight应用程序创建一个自定义控件,该控件基本上允许用户在画布上单击和拖动,并在两端绘制一条带有小矩形的线。如何将这三个控件封装到一个自定义控件中。我想做这样的事

<UserControl x:Class="Linecontrol"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <SomeAbstractGroupingContainer>
         <Line Name="ctlLine" /> 
         <Rectangle Name="rec1" />
         <Rectangle Name="rec2" />
    </SomeAbstractGroupingContainer>     
</UserControl>


你知道我可以用什么来制作AbstractGroupingContainer吗?

怎么样?

虽然我不确定这是否是绘图应用程序的正确方法(注意到jlew的?),但我会回答你的问题,希望你能找到解决方案

ItemsControl
是能够执行以下操作的基本控件:

<ItemsControl>
    <ItemsControl.Items>
        <Line Name="ctlLine" /> 
        <Rectangle Name="rec1" />
        <Rectangle Name="rec2" />
    </ItemsControl.Items>
</ItemsControl>
你可以随心所欲地扩展它

最后你会得到这样的结果:

<myControls:SomeAbstractGroupingContainer>
    <myControls:SomeAbstractGroupingContainer.Items>
        <Line Name="ctlLine" /> 
        <Rectangle Name="rec1" />
        <Rectangle Name="rec2" />
    </myControls:SomeAbstractGroupingContainer.Items>
</myControls:SomeAbstractGroupingContainer>

通过修改
控制模板
,可以更改项目的排列方式


这篇文章的灵感来源于此,可能会有所帮助。

我不需要Canvas的任何功能。这就是为什么我想找到一些抽象容器或其他解决方案的原因。这很难从问题中分辨出来,因为你似乎在它上面画画(直线和矩形)也许ItemsControl更适合您的情况?我最终不得不使用canvas,只是处理控件和画布的大小调整。使用canvas的问题是,我已经在使用一个画布,其中许多控件和其他控件将在该画布上绘制。这些控件都可以调整大小,这意味着我也必须重新调整画布的大小。我注意到itemsControl有一些布局/流行为(ala堆栈或dock面板),这对我不起作用。我只需要一个没有真正UI组件的逻辑容器。@PhilBrown您实际上不必将项目堆叠起来。您应该能够像这样覆盖
ItemsPanelTemplate
(将此添加到
中我的第一个代码示例中)这不仅仅是使用画布吗?@PhilBrown它非常类似,但是您可以有一个可以绑定数据的子控件的动态(非硬编码)集合。但是我发现您的问题已经解决了:)此外,我如何将这种类型的功能封装在一个单用户控件(使用xaml进行绑定)中,以便与其他类似的复合控件一起在画布上绘制(稍后调整或移动)呢?
<myControls:SomeAbstractGroupingContainer>
    <myControls:SomeAbstractGroupingContainer.Items>
        <Line Name="ctlLine" /> 
        <Rectangle Name="rec1" />
        <Rectangle Name="rec2" />
    </myControls:SomeAbstractGroupingContainer.Items>
</myControls:SomeAbstractGroupingContainer>