如何将 .CS 功能添加到 Silverlight 应用程序的 Expression Design 中内置的 XAML 类?

发布于 2024-09-06 21:54:47 字数 352 浏览 2 评论 0原文

如何将 .CS 功能添加到 Expression Design 中内置的 XAML 类?

我有一个设计师交给我的 Silverlight 项目,但它似乎还没有太多功能。我注意到的第一件事是,似乎没有任何相应的 .cs 文件与“LayoutRoot”的子级相匹配。我的意思是,正如在 Expression Blend 中出现的那样,这些是“LayoutRoot”下“对象和时间线选项卡”中的子节点。

在 Visual Studio 8 中查看时,它们似乎是 Page.xaml 类的子节点。第一步不应该是生成一些 .cs 文件或类来处理这些网格的功能吗?我对第一个子网格的名称进行了搜索,但在任何现有 .cs 文件中都没有得到任何结果。如何生成 .cs 文件?

How do I add .CS functionality to XAML classes built in Expression Design?

I have a Silverlight project handed to me by designers that does not seem to have much functionalty to it yet. One of the first things I have noticed is that there does not seem to be any corresponding .cs files that match up with what appears to be children of the "LayoutRoot". I mean, as it appears in Expression Blend, these are child nodes in the "Objects and Timeline Tab" under "LayoutRoot".

When viewed in Visual Studio 8, they appear to be children nodes of of the Page.xaml class. Shouldn't the first step be that I generate some .cs files or class to handle the functionality of these grids? I did a search on the name of the first child grid and I did not get any results in any of the existing .cs files. How do I generate .cs files?

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

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

发布评论

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

评论(2

攀登最高峰 2024-09-13 21:54:47

网格通常用作整个页面的容器控件。您通常不会直接处理它。如果网格中有控件,您就可以处理这些控件。给它们命名(即.. x:Name="someName"),然后处理这些控件的事件。在控件和处理事件方面,它几乎与 WinForms 完全相同。

例如,这里是来自 WPF 项目的一些 XAML(我知道它不是 Silverlight,但基本相同)。

  <Grid x:Name="LayoutRoot">
     <Canvas 
          x:Name="canvas1" 
          Height="100" 
          HorizontalAlignment="Left" 
          Margin="116,62,0,0" 
          VerticalAlignment="Top" 
          Width="200">

      </Canvas>

      <Button 
          x:Name="btnGetChildren" 
          Content="Get Children" 
          Height="23" 
          Margin="174,209,218,47" 
          Width="75" 
          Click="btnGetChildren_Click" />
  </Grid>

请注意,我在网格“内部”有一个画布和一个按钮。请注意,该按钮有一个我正在处理的 Click 事件。该单击事件的代码位于页面的“xaml.cs”文件中。

private void btnGetChildren_Click(object sender, RoutedEventArgs e)
{
    foreach (UIElement element in canvas1.Children)
    {
        // some code
    }
}

The Grid is commonly used as a container control for the entire page. You normally don't deal with it directly. If you have controls in the grid, you deal with those controls. Give them names(ie.. x:Name="someName"), then deal with the events for those controls. It's almost exactly like WinForms in regards to controls and dealing with events.

For example, here is some XAML from a WPF project(I know it's not Silverlight but basically the same)

  <Grid x:Name="LayoutRoot">
     <Canvas 
          x:Name="canvas1" 
          Height="100" 
          HorizontalAlignment="Left" 
          Margin="116,62,0,0" 
          VerticalAlignment="Top" 
          Width="200">

      </Canvas>

      <Button 
          x:Name="btnGetChildren" 
          Content="Get Children" 
          Height="23" 
          Margin="174,209,218,47" 
          Width="75" 
          Click="btnGetChildren_Click" />
  </Grid>

Notice that I have a Canvas and a Button "inside" the Grid. Notice that the button has a Click event that I am handling. The code for that click event is in the "xaml.cs" file for the page.

private void btnGetChildren_Click(object sender, RoutedEventArgs e)
{
    foreach (UIElement element in canvas1.Children)
    {
        // some code
    }
}
懒的傷心 2024-09-13 21:54:47

XAML 和 xaml.cs 文件是部分类,因此页面上的组件是该类的属性,即使您在 .cs 文件后面的代码中看不到它们。要查看其实际效果,请创建一个方法,然后在方法主体中开始键入对象的名称,您将看到它会出现在智能感知中。

另一种方法是从设计层面来处理。在属性窗口上切换到“事件”。找到您想要操作的事件并在提供的字段中键入方法名称。当您点击“Enter”时,VS 会将方法连接到事件并直接转到您刚刚创建的处理程序方法。

The XAML and xaml.cs file are partial classes so the components on the page are properties of the class even if you don't see them in the code behind .cs file. To see this in action, create a method and in the method body start typing the name of the object and you'll see it'll come up in the intellisense.

Another way is to deal with it from the design surface. On the properties window switch to "events". Find the event you want to action and type a method name in the provided field. When you hit "Enter" VS will wire up the method to the event and take to straight to the handler method you just created.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文