Content的有关问题

Content的问题


--模板里(好像是这样认为,我不懂)
<Border Background="{TemplateBinding Background}" Margin="7" Grid.Row="1">
  <ContentPresenter x:Name="ContentPresenter" Content="{TemplateBinding Content}" 
  ContentTemplate="{TemplateBinding ContentTemplate}"
  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
  </Border>



--然后
FloatableWindow fw = new FloatableWindow();
  fw.ParentLayoutRoot = LayoutRootx:Name="LayoutRoot"]
  fw.Title = "Test Floatable Window";
  fw.Content = grid1; ///怎样让grid1里的内容给到fw里显示,如果="111"一个字符串时就能显示,但我想不单传字符串的话要怎么写?
   
  fw.ShowDialog();

------解决方案--------------------
尝试在fw.ParentLayoutRoot.AddChild(grid1);
------解决方案--------------------
2楼说的对,把控件作为子控件添加到当前控件中就可以了。
------解决方案--------------------
楼主像是在写 ChildWin ,如果是在写模板化控件的话,那么这样是写可以的,不过要求 grid1 还未被添加到其他容器中。

楼主可以试一下:
fw.Content = new Grid() { Width=100,Height=100, Background=new SolidColorBrush(Colors.Red) };
看看有没有效果先。