Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8596487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:41:30+00:00 2026-06-12T00:41:30+00:00

I am trying to set a property in a usercontrol from a view model,

  • 0

I am trying to set a property in a usercontrol from a view model, the control is meant to capture and display the users signature.
I am having problems setting the property in the usercontrol from a view model.
Receiving the signature from the usercontrol into the view model works fine.

Any ideas on how to solve this would be of greatly appreciated.

My test code is below.

User control XAML:

 <UserControl x:Class="mvvmSignature.ucSignature"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="212" d:DesignWidth="300" Background="#FFEFFCEF">
    <Grid Height="210">
        <InkCanvas MinHeight="73" HorizontalAlignment="Left" Margin="10,27,0,0" Name="inkCanvas1" VerticalAlignment="Top" MinWidth="278" LostMouseCapture="inkCanvas1_LostMouseCapture" />
        <Button Content="Clear" Height="23" HorizontalAlignment="Left" Margin="33,142,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="buttonClear_Click" />
        <Button Content="Load on user control" Height="23" Margin="143,143,36,45" Click="ButtonLoad_Click" />
    </Grid>
</UserControl>

UserControl CodeBehind:

using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
namespace mvvmSignature
{
    public partial class ucSignature : UserControl
    {
        public ucSignature()
        {
            InitializeComponent();
        }
        private void inkCanvas1_LostMouseCapture(object sender, MouseEventArgs e)
        {
            SetSignature();
        }
        private void SetSignature()
        {
            var sb = new StringBuilder();
            using (var ms = new MemoryStream())
            {
                inkCanvas1.Strokes.Save(ms);
                foreach (var item in ms.ToArray())
                {
                    sb.AppendFormat("{0},",
                                        item);
                }
                ms.Close();
            }
            var local = sb.ToString().Trim() + "¬¬¬";
            local = local.Replace(",¬¬¬", string.Empty);
            Signature = local;
        }
        private void LoadSignature(string signatureIn)
        {
            if (string.IsNullOrEmpty(signatureIn) || !signatureIn.Contains(",")) return;
            var x = signatureIn.Split(',').Select(byte.Parse).ToArray();
            if (!x.Any()) return;
            using (var ms = new MemoryStream(x))
            {
                inkCanvas1.Strokes = new StrokeCollection(ms);
                ms.Close();
            }
        }
        public static DependencyProperty SignatureProperty =
        DependencyProperty.Register("Signature", typeof(string),
                                    typeof(ucSignature));
        public string Signature
        {
            get { return (string) GetValue(SignatureProperty); }
            set
            {
                SetValue(SignatureProperty, value);
                LoadSignature(value);
            }
        }
        private void ButtonLoad_Click(object sender, RoutedEventArgs e)
        {
            Signature = "0,136,3,3,6,72,16,69,53,70,53,17,0,0,128,63,31,9,17,0,0,0,0,0,0,240,63,10,237,2,186,1,135,240,12,39,128,97,109,28,4,156,51,90,235,138,135,131,227,95,107,253,119,193,35,104,195,186,246,103,1,195,179,59,78,134,195,179,92,167,188,180,76,206,211,192,77,175,108,211,28,53,136,32,51,41,156,210,3,148,109,22,188,163,105,195,188,11,92,11,184,122,101,188,166,182,124,53,106,153,90,44,217,71,15,64,102,115,59,52,205,105,1,53,128,76,166,179,73,156,202,107,0,195,248,122,106,153,64,22,185,164,210,3,51,154,64,102,51,8,5,174,105,52,128,204,102,19,57,156,215,41,90,69,162,103,1,128,76,128,19,40,4,6,1,102,153,205,96,22,105,156,206,101,53,180,89,230,83,88,4,202,107,0,179,38,120,122,215,52,195,248,120,179,101,25,158,80,195,179,41,156,210,107,50,180,205,38,144,25,156,214,105,52,153,97,249,165,166,101,52,180,205,32,48,0,135,231,164,231,113,153,131,40,225,168,4,6,1,1,128,89,160,22,105,164,214,207,135,32,56,110,3,52,153,192,96,19,80,0,11,68,6,1,105,11,76,2,215,135,50,142,28,77,48,253,160,180,225,232,12,2,107,52,128,205,38,115,91,68,214,105,51,153,77,112,238,30,77,102,80,9,148,214,1,1,154,76,230,64,38,80,8,12,2,101,50,180,205,11,70,29,128,225,236,63,0,153,77,96,19,9,141,154,207,102,153,204,230,19,24,12,209,105,154,64,96,19,89,148,204,0,76,166,118,121,132,204,77,38,179,56,13,170,3,51,128,64,109,24,126,104,154,32,54,121,148,202,103,52,153,77,96,9,144";
        }
        private void buttonClear_Click(object sender, RoutedEventArgs e)
        {
            inkCanvas1.Strokes.Clear();
            SetSignature();
        }
    }
}

MainWindow XAML:

<Window xmlns:my="clr-namespace:mvvmSignature"  x:Class="mvvmSignature.MainWindow"
    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"
    xmlns:ignore="http://www.ignore.com"
    mc:Ignorable="d ignore"
    Height="490"
    Width="327"        
    DataContext="{Binding Main, Source={StaticResource Locator}}">   
<StackPanel>
    <my:ucSignature  Signature ="{Binding Signature,Mode=TwoWay}"  />
    <Button Width ="140" Height ="30" Content ="Load On Main Page" Command="{Binding LoadOnMainPageCommand}" />
    <TextBox FontSize="8"
               Foreground="Purple"
               Text="{Binding Signature,Mode=TwoWay}"
               VerticalAlignment="Center"
               HorizontalAlignment="Center"
               TextWrapping="Wrap" Height="210" />
</StackPanel>

MainViewModel:

using System.Windows.Input;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
namespace mvvmSignature.ViewModel
{
    public class MainViewModel : ViewModelBase
    {
        public ICommand LoadOnMainPageCommand { get; set; }
        public const string WelcomeTitlePropertyName = "Signature";
        private string _signature = string.Empty;
        public string Signature 
        {
            get
            {
                return _signature;
            }
            set
            {
                if (_signature == value)
                {
                    return;
                }
                _signature = value;
                RaisePropertyChanged(WelcomeTitlePropertyName);
            }
        }

        public MainViewModel()
        {
            LoadOnMainPageCommand = new RelayCommand(LoadSignature);
        }

        private void LoadSignature()
        {
            Signature ="0,136,3,3,6,72,16,69,53,70,53,17,0,0,128,63,31,9,17,0,0,0,0,0,0,240,63,10,237,2,186,1,135,240,12,39,128,97,109,28,4,156,51,90,235,138,135,131,227,95,107,253,119,193,35,104,195,186,246,103,1,195,179,59,78,134,195,179,92,167,188,180,76,206,211,192,77,175,108,211,28,53,136,32,51,41,156,210,3,148,109,22,188,163,105,195,188,11,92,11,184,122,101,188,166,182,124,53,106,153,90,44,217,71,15,64,102,115,59,52,205,105,1,53,128,76,166,179,73,156,202,107,0,195,248,122,106,153,64,22,185,164,210,3,51,154,64,102,51,8,5,174,105,52,128,204,102,19,57,156,215,41,90,69,162,103,1,128,76,128,19,40,4,6,1,102,153,205,96,22,105,156,206,101,53,180,89,230,83,88,4,202,107,0,179,38,120,122,215,52,195,248,120,179,101,25,158,80,195,179,41,156,210,107,50,180,205,38,144,25,156,214,105,52,153,97,249,165,166,101,52,180,205,32,48,0,135,231,164,231,113,153,131,40,225,168,4,6,1,1,128,89,160,22,105,164,214,207,135,32,56,110,3,52,153,192,96,19,80,0,11,68,6,1,105,11,76,2,215,135,50,142,28,77,48,253,160,180,225,232,12,2,107,52,128,205,38,115,91,68,214,105,51,153,77,112,238,30,77,102,80,9,148,214,1,1,154,76,230,64,38,80,8,12,2,101,50,180,205,11,70,29,128,225,236,63,0,153,77,96,19,9,141,154,207,102,153,204,230,19,24,12,209,105,154,64,96,19,89,148,204,0,76,166,118,121,132,204,77,38,179,56,13,170,3,51,128,64,109,24,126,104,154,32,54,121,148,202,103,52,153,77,96,9,144";
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:41:32+00:00Added an answer on June 12, 2026 at 12:41 am

    I re-wrote portions of your ucSignature class to properly declare and use the Signature property in your code behind. Use this class definition instead, and let me know if it works any better.

    public partial class ucSignature : UserControl
    {
        public ucSignature()
        {
            InitializeComponent();
        }
    
        private void inkCanvas1_LostMouseCapture(object sender, MouseEventArgs e)
        {
            var sb = new StringBuilder();
            using (var ms = new MemoryStream())
            {
                inkCanvas1.Strokes.Save(ms);
                foreach (var item in ms.ToArray())
                {
                    sb.AppendFormat("{0},", item);
                }
                ms.Close();
            }
            var local = sb.ToString().Trim() + "¬¬¬";
            local = local.Replace(",¬¬¬", string.Empty);
    
            this.SetValue(SignatureProperty, local);
        }
    
        private void LoadSignature(string signatureIn)
        {
            if (string.IsNullOrEmpty(signatureIn) || !signatureIn.Contains(",")) return;
            var x = signatureIn.Split(',').Select(byte.Parse).ToArray();
            if (!x.Any()) return;
            using (var ms = new MemoryStream(x))
            {
                inkCanvas1.Strokes = new StrokeCollection(ms);
                ms.Close();
            }
        }
    
        public static DependencyProperty SignatureProperty = DependencyProperty.Register(
            "Signature",
            typeof(string),
            typeof(ucSignature),
            new UIPropertyMetadata(OnSignaturePropertyChanged));
    
        public static string GetSignature(ucSignature signature)
        {
            return (string)signature.GetValue(SignatureProperty);
        }
    
        public static void SetSignature(ucSignature signature, string value)
        {
            signature.SetValue(SignatureProperty, value);
        }
    
        private static void OnSignaturePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            var signature = obj as ucSignature;
    
            if (signature != null)
            {
                LoadSignature(args.NewValue.ToString());
            }
        }
    
        private void ButtonLoad_Click(object sender, RoutedEventArgs e)
        {
            this.SetValue(SignatureProperty, "0,136,3,3,6,72,16,69,53,70,53,17,0,0,128,63,31,9,17,0,0,0,0,0,0,240,63,10,237,2,186,1,135,240,12,39,128,97,109,28,4,156,51,90,235,138,135,131,227,95,107,253,119,193,35,104,195,186,246,103,1,195,179,59,78,134,195,179,92,167,188,180,76,206,211,192,77,175,108,211,28,53,136,32,51,41,156,210,3,148,109,22,188,163,105,195,188,11,92,11,184,122,101,188,166,182,124,53,106,153,90,44,217,71,15,64,102,115,59,52,205,105,1,53,128,76,166,179,73,156,202,107,0,195,248,122,106,153,64,22,185,164,210,3,51,154,64,102,51,8,5,174,105,52,128,204,102,19,57,156,215,41,90,69,162,103,1,128,76,128,19,40,4,6,1,102,153,205,96,22,105,156,206,101,53,180,89,230,83,88,4,202,107,0,179,38,120,122,215,52,195,248,120,179,101,25,158,80,195,179,41,156,210,107,50,180,205,38,144,25,156,214,105,52,153,97,249,165,166,101,52,180,205,32,48,0,135,231,164,231,113,153,131,40,225,168,4,6,1,1,128,89,160,22,105,164,214,207,135,32,56,110,3,52,153,192,96,19,80,0,11,68,6,1,105,11,76,2,215,135,50,142,28,77,48,253,160,180,225,232,12,2,107,52,128,205,38,115,91,68,214,105,51,153,77,112,238,30,77,102,80,9,148,214,1,1,154,76,230,64,38,80,8,12,2,101,50,180,205,11,70,29,128,225,236,63,0,153,77,96,19,9,141,154,207,102,153,204,230,19,24,12,209,105,154,64,96,19,89,148,204,0,76,166,118,121,132,204,77,38,179,56,13,170,3,51,128,64,109,24,126,104,154,32,54,121,148,202,103,52,153,77,96,9,144");
        }
        private void buttonClear_Click(object sender, RoutedEventArgs e)
        {
            inkCanvas1.Strokes.Clear();
            this.SetValue(SignatureProperty, string.Empty);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to bind a Dependency Property from my UserControl to my MainViewModel. This
Trying to access a property from the parent page on my user control. Here's
I am trying to set textColor property of button in android 2.1. But I
Is this possible in javascript? I'm trying to set the property name of an
Pardon me if it is nave; but i am trying to set a property
I'm trying to set the ForceCheckout property on an SPList item and it's just
I'm trying to set the width & height property of an image element i've
I've been trying to read and set the departmentNumber property for a DirectoryEntry object
This is what I am trying to achieve: if a property is set then
I'm trying to use mock to verify that an index property has been set.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.