x:Silverlight 中的共享标记扩展

发布于 2025-01-07 13:46:13 字数 821 浏览 0 评论 0原文

silverlight 中缺少 x:Shared MarkupExtension 是否有解决方法?

我有以下 Xaml,它在每个目标系列上创建一个椭圆。我需要椭圆是唯一的,因为它们稍后会添加到画布中。通过使用此 Xaml,我收到以下错误:UIElement 已添加到另一个父级(例如,单个 Ellipse 实例多次添加到 Canvas)。

在 WPF 中,我只需使用此样式的 x:Shared 属性即可使其正常工作。

    <!-- Set the style for the series -->
    <Style TargetType="SciChart:FastLineRenderableSeries" >
        <Setter Property="SeriesColor" Value="#FF93F2C1"/>
        <Setter Property="ResamplingMode" Value="Mid"/>
        <Setter Property="RolloverMarker">
            <Setter.Value>
                <Ellipse Width="9" Height="9" Fill="#7793F2C1" Stroke="#FFA3FFC9"/>
            </Setter.Value>
        </Setter>
    </Style>

我考虑的解决方法是创建一个名为 RolloverMarker 的控件并设置其控件模板。我将不胜感激任何直接或间接解决此问题的方法。

Is there a workaround for the missing x:Shared MarkupExtension in silverlight?

I have the following Xaml which is creating an ellipse on each target series. I need the ellipses to be unique as they are later added to canvas. By using this Xaml I get the error that the UIElement has already been added to another parent (e.g. single Ellipse instance added to Canvas multiple times).

In WPF I simply use the x:Shared property on this style to get it to work.

    <!-- Set the style for the series -->
    <Style TargetType="SciChart:FastLineRenderableSeries" >
        <Setter Property="SeriesColor" Value="#FF93F2C1"/>
        <Setter Property="ResamplingMode" Value="Mid"/>
        <Setter Property="RolloverMarker">
            <Setter.Value>
                <Ellipse Width="9" Height="9" Fill="#7793F2C1" Stroke="#FFA3FFC9"/>
            </Setter.Value>
        </Setter>
    </Style>

A workaround I considered was to create a control called RolloverMarker and set its control template. I'd appreciate any direct or indirect solutions to this problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唱一曲作罢 2025-01-14 13:46:13

如果您动态地将对象添加到面板,则每次都需要创建一个新对象,或者您需要在某种模板中定义控件并添加将使用该模板的新数据对象。您不能多次添加同一项目。

例如,

// Does not work
var templateItem = new FastLineRenderableSeries();
myCanvas.Add(templateItem);
myCanvas.Add(templateItem);


// Works
myCanvas.Add(new FastLineRenderableSeries());
myCanvas.Add(new FastLineRenderableSeries());

或者

<ItemsControl ItemsSource="{Binding SomeCollection}"
              ItemTemplate="{StaticResource FastLineRenderableSeriesStyle}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Canvas />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>
// Add items. They'll get rendered with defined ItemStyle.
var templateItem = new FastLineRenderableSeries();
SomeCollection.Add(templateItem);
SomeCollection.Add(templateItem);

If you are dynamically adding objects to a panel, then a new object needs to be created each time, or you need to define your control in some kind of Template and add a new data object which will use the Template. You cannot add the same item multiple times.

For example,

// Does not work
var templateItem = new FastLineRenderableSeries();
myCanvas.Add(templateItem);
myCanvas.Add(templateItem);


// Works
myCanvas.Add(new FastLineRenderableSeries());
myCanvas.Add(new FastLineRenderableSeries());

Or

<ItemsControl ItemsSource="{Binding SomeCollection}"
              ItemTemplate="{StaticResource FastLineRenderableSeriesStyle}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Canvas />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>
// Add items. They'll get rendered with defined ItemStyle.
var templateItem = new FastLineRenderableSeries();
SomeCollection.Add(templateItem);
SomeCollection.Add(templateItem);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文