Note that there are some explanatory texts on larger screens.

plurals
  1. POUserControl throws System.ArgumentException
    text
    copied!<p>Hi i'm using an userControl it works fine but when i try to use it for second time it throws the next exception </p> <p><strong>An unhandled exception of type 'System.ArgumentException' occurred in System.Windows.dll Additional information: The parameter is incorrect.</strong> </p> <p>Here's my code </p> <p>XAML</p> <pre><code> &lt;Grid x:Name="LayoutRoot"&gt; &lt;TextBlock x:Name="tb1" FontWeight="ExtraBold" Foreground="Black" Opacity="0.7" Margin="1,3,0,0" Text="{Binding Text,ElementName=me}" TextWrapping="Wrap" /&gt; &lt;TextBlock x:Name="tb2" FontWeight="ExtraBold" Foreground="Black" Opacity="0.7" Margin="1,3,0,0" Text="{Binding Text,ElementName=tb1}" TextWrapping="Wrap" /&gt; &lt;TextBlock x:Name="tb3" FontWeight="ExtraBold" Foreground="Black" Opacity="0.7" Margin="1,3,0,0" Text="{Binding Text,ElementName=tb1}" TextWrapping="Wrap" /&gt; &lt;TextBlock x:Name="tb4" FontWeight="ExtraBold" Foreground="Black" Opacity="0.7" Margin="1,3,0,0" Text="{Binding Text,ElementName=tb1}" TextWrapping="Wrap" /&gt; &lt;TextBlock x:Name="tb5" FontWeight="ExtraBold" Foreground="Black" Opacity="0.7" Margin="1,3,0,0" Text="{Binding Text,ElementName=tb1}" TextWrapping="Wrap" /&gt; &lt;TextBlock x:Name="tb6" FontWeight="ExtraBold" Foreground="Black" Opacity="0.7" Margin="1,3,0,0" Text="{Binding Text,ElementName=tb1}" TextWrapping="Wrap" /&gt; &lt;TextBlock x:Name="tb7" FontWeight="ExtraBold" Foreground="Black" Opacity="0.7" Margin="1,3,0,0" Text="{Binding Text,ElementName=tb1}" TextWrapping="Wrap" /&gt; &lt;TextBlock x:Name="tb8" FontWeight="ExtraBold" Foreground="White" Text="{Binding Text,ElementName=tb1}" TextWrapping="Wrap" /&gt; &lt;/Grid&gt; </code></pre> <p>C#</p> <pre><code> public partial class DropShadowTextBlock : UserControl { public DropShadowTextBlock() { InitializeComponent(); } public string Text { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } } public SolidColorBrush Foreground { get { return (SolidColorBrush)GetValue(ForegroundProperty); } set { SetValue(ForegroundProperty,value);} } public static void ForegroundPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { DropShadowTextBlock control = sender as DropShadowTextBlock; if (control != null) { control.tb8.Foreground = e.NewValue as SolidColorBrush; } } public static void TextPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { var control = sender as DropShadowTextBlock; if (control.tb1 != null) control.tb1.Text = e.NewValue.ToString(); } public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(DropShadowTextBlock), new PropertyMetadata(new PropertyChangedCallback(TextPropertyChanged))); public static readonly DependencyProperty ForegroundProperty = DependencyProperty.Register("Foreground", typeof(SolidColorBrush), typeof(DropShadowTextBlock), new PropertyMetadata(new PropertyChangedCallback(ForegroundPropertyChanged))); } } </code></pre> <p>And finally here's how i use the userControl</p> <pre><code> public void dibujarTexto(String text) { DropShadowTextBlock textblockTop = new DropShadowTextBlock(); textblockTop.Text = text; textblockTop.Foreground = new SolidColorBrush(Colors.White); textblockTop.Name = Guid.NewGuid().ToString(); migrid.Children.Add(textblockTop); //this is a grid control } </code></pre> <p>I've been sharing and i found that the control names must be unique so i'm using the Guid class to get random names but doesn't work</p> <p>Please if somebody could help me.</p> <p>Thanks best regards.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload