English 中文(简体)
几个具有共同控制的银星应用将采取什么良好做法?
原标题:What would be a good approach for several Silverlight applications with common controls?

我只字不提银灯,必须编辑数份SL申请,这些申请将有许多内容。

我计划把所有共同的C#代码放在一个分离的集会上,但我确实知道XAML部分。

我的所有申请都将有一些共同的控制:

  • a menu bar at the top,
  • a toolbar at the top,
  • a status bar at the bottom,
  • a panel on the left.

我搜索了网络,发现XAML代码不能继承。

因此,我想建立一种包含我共同控制的大习俗控制,然后在我的所有申请的主页上添加这一控制,但这似乎不是正确的。

有哪些最佳做法?

感谢任何帮助,

http://www.un.org。 我想在这里做的是,我与温福派已经做过的事情。 我建立了一个“温树基地”,并对它进行一些控制。 然后,当我创立了新温树,继承了这一“温树基”时,他们拥有所有的基本控制。 我不得不使用任何习俗控制。

但我的理解是,银星不是WinForm,而我所希望的这种方式(或根本上)是行不通的。

最佳回答

这取决于你想要走的路,取决于你是否想要把一个资源存档,备有某些模板等,这些模板被适当复制/连接到每项申请中,或者使用共同的DL中包含的内容。

If you want to do the latter, here s one approach. Subclass ContentControl to define your common layout in its control template (you can do this all in XAML), including a binding to its Content in the appropriate place:

<ContentControl x:Class="MyLibrary.MyLayoutControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ContentControl.Template>
        <ControlTemplate TargetType="ContentControl">
            <!-- this could be a layout grid with various other controls in it -->
            <Border BorderBrush="Red" BorderThickness="2" CornerRadius="5">
                <ContentPresenter Content="{TemplateBinding Content}" />
            </Border>
        </ControlTemplate>
    </ContentControl.Template>
</ContentControl>

Then use it in your application root control:

<UserControl x:Class="InCustomControlTest.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:c="clr-namespace:MyLibrary;assembly=MyLibrary">

    <c:MyLayoutControl>
        <Button Content="Hi I am a button" />
    </c:MyLayoutControl>
</UserControl>

如果你想做一些更复杂的事,那么你就应当进行习俗控制;尽管在大多数情形下,你可能能够放弃几个用户对你们进入正确位置的各个组成部分(例如,你的地位酒吧)的看法。

问题回答

There is no big problem putting xaml resources in library projects. When referencing resourcedictionaries from other projects, be sure to include the assembly name. Also there is inheritance on templates, where you can put BasedOn attribute.

Edit: well, looking at the project we worked on some time ago, I now remember we actually had problems with it and had the xaml resources copied to each project... I forgot =) I think it worked but brought some problems here and there. Maybe add the xaml files as links?

Personally I would also not create to many controls, rather have templates for most stuff. If you have controls, better write them in c# only with usage of templates, preventing xaml with code behinds. Just my personal experience, might not be the common guideline.





相关问题
Subclass check, is operator or enum check

A couple of friends was discussing the use of inheritance and how to check if a subclass is of a specific type and we decided to post it here on Stack. The debate was about if you should implement a ...

C++ Class Inheritance problem

Hi I have two classes, one called Instruction, one called LDI which inherits from instruction class. class Instruction{ protected: string name; int value; public: Instruction(string ...

Overloading a method in a subclass in C++

Suppose I have some code like this: class Base { public: virtual int Foo(int) = 0; }; class Derived : public Base { public: int Foo(int); virtual double Foo(double) = 0; }; ...

Embedding instead of inheritance in Go

What is your opinion of this design decision? What advantages does it have and what disadvantages? Links: Embedding description

Extending Flex FileReference class to contain another property

I want to extend the FileReference class of Flex to contain a custom property. I want to do this because AS3 doesn t let me pass arguments to functions through event listeners, which makes me feel sad,...

Interface Inheritance in C++

I have the following class structure: class InterfaceA { virtual void methodA =0; } class ClassA : public InterfaceA { void methodA(); } class InterfaceB : public InterfaceA { virtual ...

热门标签