0

This is my C#, it appears to load the Xaml just fine, all the children are in R1C3Viewbox as well as the data they contain. But nothing displays on screen.

ParserContext context = new ParserContext();
context.XmlnsDictionary.Add("", 
"http://schemas.microsoft.com/winfx/2006/xaml/presentation");
context.XmlnsDictionary.Add("x", 
"http://schemas.microsoft.com/winfx/2006/xaml");

using (FileStream fs = new FileStream("R1C3Viewbox.xaml", FileMode.Open))
    {
      R1C3Viewbox = (Viewbox)XamlReader.Load(fs, context);
    }

The xaml file contains:

<Viewbox Name="R1C3Viewbox" Grid.Row="1" Grid.Column="6" Grid.ColumnSpan="1" 
Grid.RowSpan="1">
  <Border Name="R1C3Border" BorderBrush="Black" CornerRadius="3" 
  BorderThickness="1" Background="#FFFFC602" Height="40" Width="40" 
  Margin="3,3,0,0">
    <Grid Name="R1C3Grid">
      <TextBlock Name="R1C3TextBlock1" FontFamily="Arial" FontSize="10" 
       FontWeight="Bold" Text="RAPID" Foreground="Black" 
       Margin="4,12,0,15"/>
      <TextBlock Name="R1C3TextBlock2" FontFamily="Arial" FontSize="10" 
      FontWeight="Bold" Text="OVER" Foreground="Black" Margin="5,23,5,3"/>
      <Polygon Name="R1C3LED" Points="0,0 15,0 0,15" Stroke="#FFED1C24" 
       StrokeThickness="1"> 
       <Polygon.Fill> <RadialGradientBrush> <GradientStop Color="White" 
       Offset="2.5"/> <GradientStop Color="Black"/> </RadialGradientBrush> 
       </Polygon.Fill>
       </Polygon>
       <Button Name="R1C3Button" Background="Transparent" 
        BorderBrush="Transparent"></Button>
      </Grid>
     </Border>
   </Viewbox>

Any thoughts would be greatly appreciated.

  • 1
    Are you doing anything with R1C3Viewbox after loading the XAML? There is no built-in magic that makes it automatically "display on screen". – Clemens May 09 '17 at 21:28
  • No. The framework for R1C3Viewbox (and it's children) pre-exists in the MainWindow.xaml and I'm able to set the content and properties in the code behind with simple statements: R1C3Border.BorderBrush = new SolidColorBrush(Colors.Black); R1C3Border.CornerRadius = new CornerRadius(3); I thought that Xamlreader would be a more concise way to set content and properties of elements rather than parsing the xaml myself and setting the Viewbox (and its children) properties and content individually. – user3352918 May 10 '17 at 11:09

0 Answers0