Link to home
Create AccountLog in
Avatar of jdavey3
jdavey3

asked on

Save an inkcanvas and its contents to and xml file

Below I have an inkcanvas which when the application is running that the user can change the size and colour of the textblock, can I save the changed version of this canvas to a file and store it in a node in a xml file when that user logins in that that canvas can be read and displayed on screen ?
<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Class="movetext2.Window1"
        Title="InkCanvas"
        Width="640" Height="400">
        <Window.Resources>
 
    <Style TargetType="Rectangle">
 
      <Setter Property="Width" Value="50"/>
 
      <Setter Property="Height" Value="75"/>
 
    </Style>
 
  </Window.Resources>
 
 
 
        <Grid>    
 
    <InkCanvas x:Name="IC1" EditingMode="Select"
 
               Background="LightGoldenrodYellow"
 
               SelectionChanging="OnSelectionChanging" HorizontalAlignment="Left" Margin="3,4,0,54" Width="306">
 
      
 
      <!-- InkCanvas' Child Elements -->
 
    <!--  <Rectangle InkCanvas.Left="20" InkCanvas.Top="20" Fill="Blue"/>
 
      <Rectangle InkCanvas.Right="80" InkCanvas.Bottom="30" Fill="Green"/>
 
      <Rectangle Margin="50,150,20,20"  Fill="Orange"/> -->
 
      <Rectangle Visibility="Visible">
                <Rectangle.Fill>
                    <VisualBrush>
                        <VisualBrush.Visual>
                            <StackPanel>
                                <TextBlock HorizontalAlignment="Left" Margin="-45,-52,0,0" x:Name="txtb1" VerticalAlignment="Top" Width="40" Height="30" Text="I" TextWrapping="Wrap"/>
                            </StackPanel>
                        </VisualBrush.Visual>
                    </VisualBrush>          
                </Rectangle.Fill>
                <Rectangle.RenderTransform>
                 <TranslateTransform X="30" Y="30"/>
               </Rectangle.RenderTransform>
 
      </Rectangle>
          
          <Rectangle>
                <Rectangle.Fill>
                    <VisualBrush>
                        <VisualBrush.Visual>
                            <StackPanel>
                                <TextBlock HorizontalAlignment="Left" Margin="-45,-52,0,0" x:Name="txtb2" VerticalAlignment="Top" Width="40" Height="30" Text="I" TextWrapping="Wrap"/>
                            </StackPanel>
                        </VisualBrush.Visual>
                    </VisualBrush>          
                </Rectangle.Fill>
                <Rectangle.RenderTransform>
                 <TranslateTransform X="90" Y="30"/>
               </Rectangle.RenderTransform>
 
      </Rectangle>
          
          <Rectangle>
                <Rectangle.Fill>
                    <VisualBrush>
                        <VisualBrush.Visual>
                            <StackPanel>
                                <TextBlock HorizontalAlignment="Left" Margin="-45,-52,0,0" x:Name="txtb3" VerticalAlignment="Top" Width="40" Height="30" Text="I" TextWrapping="Wrap"/>
                            </StackPanel>
                        </VisualBrush.Visual>
                    </VisualBrush>          
                </Rectangle.Fill>
                <Rectangle.RenderTransform>
                 <TranslateTransform X="150" Y="30"/>
               </Rectangle.RenderTransform>
 
      </Rectangle>
           <Rectangle>
                <Rectangle.Fill>
                    <VisualBrush>
                        <VisualBrush.Visual>
                            <StackPanel>
                                <TextBlock HorizontalAlignment="Left" Margin="-45,-52,0,0" x:Name="txtb4" VerticalAlignment="Top" Width="40" Height="30" Text="I" TextWrapping="Wrap" Visibility="Hidden"/>
                            </StackPanel>
                        </VisualBrush.Visual>
                    </VisualBrush>          
                </Rectangle.Fill>
                <Rectangle.RenderTransform>
                 <TranslateTransform X="220" Y="30"/>
               </Rectangle.RenderTransform>
 
      </Rectangle>
 
        <!-- <TextBlock OpacityMask="#FFBF8F8F" RenderTransformOrigin="0.492,0.578" x:Name="Txtb1" Width="59" Height="64" Background="#FFE7DBDB" Foreground="#FF614747" Text="Cat" TextWrapping="Wrap"/>
        <Rectangle Fill="#FFFFFFFF" Stroke="#FF000000" RadiusX="10" RadiusY="20" Margin="0,0,10,20" OverridesDefaultStyle="False" Width="83" Height="45"/>  -->
 
      
 
    </InkCanvas>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ZachSmith
ZachSmith
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of jdavey3
jdavey3

ASKER

How can I 'save the specific properties that are modifiable by the user to an XML file. Then, when the application is opened again, you can read that XML file and use it's data to set the properties of the canvas'.
The user can alter the size and colour and font of the text in the textblock and I want to record this and when the user logs in again that the text is displayed at the same size and colour that it was changed to previously.