首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > CAD教程 >

动态加载Xaml字符串(相当于批量生成控件)的有关问题

2012-03-22 
动态加载Xaml字符串(相当于批量生成控件)的问题页面Xaml的设计如下:navigation:Page x:ClassdogGis.Sea

动态加载Xaml字符串(相当于批量生成控件)的问题
页面Xaml的设计如下:
<navigation:Page x:Class="dogGis.Search.innerPages.search_sun" 
  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"
  mc:Ignorable="d"
  xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
  d:DesignWidth="252" d:DesignHeight="300"
  Title="search_sun Page" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
   
  <Grid x:Name="LayoutRoot" Width="250">
  <Grid.RowDefinitions>
  <RowDefinition Height="60" /><!--查询条件栏-->
  <RowDefinition Height="*" /><!--查询结果栏-->
  </Grid.RowDefinitions>

  <Grid Grid.Row="0" HorizontalAlignment="Left" Name="conditionGrid" VerticalAlignment="Top">
  <Grid.ColumnDefinitions>
  <ColumnDefinition Width="50"/>
  <ColumnDefinition Width="140"/>
  <ColumnDefinition Width="50" />
  </Grid.ColumnDefinitions>

  <Grid.RowDefinitions>
  <RowDefinition Height="20" />
  <RowDefinition Height="20" />
  <RowDefinition Height="20" />
  </Grid.RowDefinitions>
   
  <TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" Text="建设单位:" VerticalAlignment="Top" />
  <TextBlock Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" Text="项目名称:" VerticalAlignment="Top" />
  <TextBox Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Name="buildCompany" VerticalAlignment="Top" Width="130" />
  <TextBox Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Name="projectName" VerticalAlignment="Top" Width="130" />
  <Button Content="查找一下" Grid.Row="1" Grid.Column="2" Height="23" HorizontalAlignment="Left" Name="searchBtn" VerticalAlignment="Center" Click="searchBtn_Click" />
  </Grid>
   
  <Grid Name="innerGrid" Grid.Row="1">
  <Grid.RowDefinitions>
  <RowDefinition Height="*" /> 
  <RowDefinition Height="20" />  
  </Grid.RowDefinitions>

  <Border Grid.Row="0" >
  <ScrollViewer Margin="3,3,3,3" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"  
  BorderBrush="Transparent" BorderThickness="0" >
  <StackPanel Orientation="Vertical">
  <sdk:DataGrid Name="dataGridView" AutoGenerateColumns="False" HorizontalAlignment="Left" VerticalAlignment="Top" />


  </StackPanel>
  </ScrollViewer>
  </Border>
  <sdk:DataPager Name="dataPagerSelect" Grid.Row="1" HorizontalAlignment="Left" PageSize="10" VerticalAlignment="Bottom" />
  </Grid>  
  </Grid>
</navigation:Page>

现在想采用网页“http://www.silverlightchina.net/html/tips/2011/1007/10792.html”的方法动态加载Xaml,生成UIElement 。我试了好多次,真是折磨人,都不能生成功,想请大家直接帮忙修改,好直接使用。谢谢

[解决办法]
请问在加载过程中,出现了什么错误?

请参考:

http://silverlightchina.net/html/tips/2011/0602/8037.html
http://silverlightchina.net/html/tips/2011/0926/10670.html
http://silverlightchina.net/html/tips/2011/1110/11652.html
http://silverlightchina.net/html/tips/2011/1223/12780.html
http://silverlightchina.net/html/tips/2012/0113/13297.html
http://silverlightchina.net/html/tips/2011/0707/8845.html

[解决办法]
string xaml = "<Button xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' Content='Button' Height='23' HorizontalAlignment='Left' VerticalAlignment='Top' Width='75' />";
Button _button=(Button)XamlReader.Load(xaml);
_button.Click += new RoutedEventHandler(button3_Click);
Grid.SetColumn(_button, 1);
Grid.SetRow(_button, 2);
LayoutRoot.Children.Add(_button);

[解决办法]
如果控件比较多的话,建议你做成控件方式.
[解决办法]

探讨
现在想采用网页“http://www.silverlightchina.net/html/tips/2011/1007/10792.html”的方法动态加载Xaml,生成UIElement 。我试了好多次,真是折磨人,都不能生成功,想请大家直接帮忙修改,好直接使用。谢谢

热点排行