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 8006391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:30:00+00:00 2026-06-04T17:30:00+00:00

I am using a usercontrol inside a grid. This usercontrol contains a textbox that

  • 0

I am using a usercontrol inside a grid. This usercontrol contains a textbox that is bound a property of an object supplied by the viewmodel. My problem is the property can be rather a string or a int.

I set the dependency property to be a string so it’s working fine for displaying but if the user enters a string into a int field, no validation error is thrown by the view model but of course i can’t save to the database.

usercontrol XAML

<UserControl x:Class="GenericFileTransferClient.Views.UserControlTextBox"
             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="300" d:DesignWidth="300">
    <Grid Name="GridLayout">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="3*"/>
            <ColumnDefinition Width="7*"/>
        </Grid.ColumnDefinitions>
        <TextBlock Text="{Binding Path=LabelText}" VerticalAlignment="Center" Style="{StaticResource ResourceKey=TextBlockWrapping}" />
        <DockPanel Grid.Column="1">
            <Border DockPanel.Dock="Right"
                                ToolTip="" Style="{StaticResource BorderReportDetail}">
                <TextBlock Text="?" Style="{StaticResource TextBoxReportDetail}"></TextBlock>
            </Border>
            <TextBox Text="{Binding Path=TextBoxText}"/>
        </DockPanel>
    </Grid>
</UserControl>

usercontrol code behind

public partial class UserControlTextBox : UserControl
{
    public static DependencyProperty LabelTextProperty = DependencyProperty.Register("LabelText", typeof(String), typeof(UserControl));
    public static DependencyProperty TextBoxTextProperty = DependencyProperty.Register("TextBoxText", typeof(String), typeof(UserControl));


    public String LabelText
    {
        get { return (String)GetValue(LabelTextProperty); }
        set { SetValue(LabelTextProperty, value); }
    }

    public String TextBoxText
    {
        get { return (String)GetValue(TextBoxTextProperty); }
        set { SetValue(TextBoxTextProperty, value); }
    }

    public UserControlTextBox()
    {
        InitializeComponent();
        GridLayout.DataContext = this;
    }
    }

example of call of the usercontrol in the main grid

<views:UserControlTextBox LabelText="Report Name:" TextBoxText="{Binding Path=CurrentReport.ReportName}" Grid.Row="1" Grid.ColumnSpan="2"/>

            <TextBlock Text="Header:" Grid.Row="2"/>
            <CheckBox Grid.Column="1" Grid.Row="2" IsChecked="{Binding Path=CurrentReport.Header}" 
                      VerticalContentAlignment="Stretch" VerticalAlignment="Center" Name="HeaderCheckBox"/>

            <Grid Grid.Row="3" Grid.ColumnSpan="2" Visibility="{Binding IsChecked, ElementName=HeaderCheckBox, Converter={StaticResource BoolToVisConverter}}">

                <views:UserControlTextBox LabelText="# Row Header:" TextBoxText="{Binding Path=CurrentReport.HeaderRow}"/>
            </Grid>

As you can see, CurrentReport.ReportName is a string but CurrentReport.HeaderRow is a int.

Is there any way to make the dependency property generic or based on a parameter passed to the usercontrol. Or is there any way of having validation to kick in before the user clicks the save button?

Thank you

  • 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-04T17:30:03+00:00Added an answer on June 4, 2026 at 5:30 pm

    I would write a simple IntToStringConverter and then use that in your TextBoxText binding to pass in a string to your usercontrol.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have 2 textbox controls inside a usercontrol TextBoxUC.ascx i have a page.aspx that
I have a user control that i am using inside a DataTemplate , this
I have a UserControl that contains a ListBox that is bound to a CollectionViewSource
i'm facing a problem tryin to execute a simples jquery inside my userControl. This
I'm using AJAX.Net (3.5) inside a usercontrol. The usercontrol contains an UpdatePanel, and inside
By Using reflector you can see that WPF UserControl is overriding AdjustBranchSource. internal override
I developing a usercontrol in csharp in which i will be using a textbox
I have an UserControl and in it, a DropDownList. I'm using this code to
I have a usercontrol that can be used in for example a gridview itemtemplate,
I've got a UserControl that contains a button and some other controls: <UserControl> <StackPanel>

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.