gpt4 book ai didi

windows-phone-7.1 - 在 Windows Phone 的页面中添加用户控件

转载 作者:行者123 更新时间:2023-12-04 07:44:00 25 4
gpt4 key购买 nike

我有一个 Windows Phone 应用程序,我需要将用户控件添加到其中一个页面。我想像在 asp.net 页面中一样添加它,而不是作为弹出窗口。如何将此用户控件添加到页面?

最佳答案

假设您的 UserControl 的格式如下:

<UserControl x:Class="UserControlExample.NameReporter"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >

<!-- Controls here -->

</UserControl>

默认情况下,当您创建一个新的 UserControl 时它应该是这样的,后面的代码类似于

using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace UserControlExample
{
public partial class NameReporter : UserControl
{
public NameReporter()
{
InitializeComponent();
}

// your custom methods here
}
}

然后您应该能够使用类似于以下的代码将其添加到页面中

<Grid xmlns:src="clr-namespace:UserControlExample" 
Background="White" Margin="0,50,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<src:NameReporter Grid.Row="0"/>
<src:NameReporter Grid.Row="1" Margin="0,15,0,0"/>
</Grid>

只需更改clr-namespace: 之后的命名空间即可和 src: 之后的控件名称

你可以把xmlns:标记到 <phone:PhoneApplicationPage>标记而不是在整个表单中使用控件(而不仅仅是在网格中),您可以更改 src无论您希望将其称为什么。

如果正确创建了 UserControl,编译解决方案应该意味着它也会出现在您的工具箱中以供使用,因此您只需拖放即可。

请参阅引用资料以获取更完整的示例。

References:

http://msdn.microsoft.com/en-us/library/system.windows.controls.usercontrol%28v=VS.95%29.aspx

关于windows-phone-7.1 - 在 Windows Phone 的页面中添加用户控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11082416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com