开发者

Two usercontrols per page in silverlight?

Is it possible to have two controls on one page side-by-side in Silverlight? It seems very restrictive to have just one user control on just one page.

I am new to silverlight. But each page seems to have this "UserControl x:Class..." at the top of the main page XAML. So what if you want to have an app where there are two side-by-side that influences each other?

OK, it is not in the App, it is in the page.xaml. So I guess to explain further let me ask this. Is it possible to have two pages in onw app?

I am trying to have two prebuilt controls (a visi control and a vectorlight tree control) on the same page. The format of the app looks something like this:

Two usercontrols per page in silverlight?

So I want a tree view on the left side and the visi control on the right side of one app. Is this possi开发者_StackOverflowble?

The tree view example has this user control code

<UserControl x:Class="TreeViewProgrammatic.Page"

xmlns="http://schemas.microsoft.com/client/2007"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:liquidTreeView="clr-namespace:Liquid;assembly=Liquid.TreeView"

Width="400" Height="300">

and the other control has a user control code like this:

<UserControl x:Class="LiveUpdate.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
Width="500" Height="340">

is there a way of having the two on one page.xaml?


I'll have at interpretting your requirements. You have two derivatives of UserControl containing in part some third party controls (actually irrelevant to the requirement) and some of your own code to make these controls do things that you want them to.

Now you'd like to have them both visible to the user side by side, they interact with one another so its desirable that they run in same Silverlight app.

You've called both of them "Page" but then placed them in their own namespace (probably because you've actually created two probjects). So first step is to create a new silverlight application and put them both in this same project, lets call the project "Xarzu1", lets also rename your UserControl derivatives to TreeViewProgrammatic and LiveUpdate so we don't have two controls with the useless name of "Page".

Now edit the MainPage.xaml so that it looks like this:-

<UserControl x:Class="Xarzu1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Xarzu1"
    mc:Ignorable="d"
    d:DesignHeight="400" d:DesignWidth="800">
     <Grid x:Name="LayoutRoot">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="2*" />
        </Grid.ColumnDefinitions>
        <local:TreeViewProgrammatic />
        <local:LiveUpdate />
    </Grid>
</UserControl>

Now both your controls are display side by side.


Thinking I understand what you mean, the Page is a control itself (the root control) and can contain controls; initially it should contain a Grid which spans the size of the Page, this means you can place a control in the Grid to consume all space on the Page. We can, though, define Columns and Rows within the Grid, so, consider this:

<Grid>
  <Grid.ColumnDefinitions>
      <ColumnDefinition />
      <ColumnDefinition />
  </Grid.ColumnDefinitions>

  <TextBlock Grid.Column="0" Text="I'm on the left side!" />
  <TextBlock Grid.Column="1" Text="I'm on the right side!" />
</Grid>

The same applies to custom UserControl items - that itself is the root control and those added to it are children, this is what makes up a composite control.


Do you get any error while instanciating 2 instances of a user control? As far as I know it should be possible to have multiple user controls in a silverlight page. Can you post some code about what you are trying to do?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜