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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:13:03+00:00 2026-05-18T03:13:03+00:00

I have a user control that displays objects of a client-declared type with some

  • 0

I have a user control that displays objects of a client-declared type with some specialized behavior. I would like to use generics. However, I’m not sure how to declare this in the XAML:

<local:EditableListBox x:Name="SectionList" Margin="56,8,15,0" FontSize="64" SelectionChanged="SectionList_SelectionChanged" />

ListBox uses object members, which makes me think that perhaps there’s no way to have type safety here. Or is there?

(I’m building a Windows Phone 7 app, if it makes any difference.)

Update: I’m totally fine with not having generics in the XAML, but I’m still trying to figure out how to set it up in the code-behind. I parameterized everything, but it’s still complaining.

Code behind:

public partial class EditableListBox<T> : UserControl, INotifyPropertyChanged where T : IEditableListMember {

    public EditableListBox()
    {
        // Error: The name 'InitializeComponent' does not exist in the current context
        InitializeComponent();
        Loaded += new RoutedEventHandler(EditableListBox_Loaded);
    }

    // ...

    public int SelectedIndex
    {
        get
        {
            // Error: The name 'ContentListBox' does not exist in the current context   
            return ContentListBox.SelectedIndex;
        }
        set
        {
            // Error: The name 'ContentListBox' does not exist in the current context   
            ContentListBox.SelectedIndex = value;
        }
    }

The XAML:

<Grid x:Name="LayoutRoot">
    <ListBox x:Name="ContentListBox">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid ManipulationCompleted="Grid_ManipulationCompleted">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <Image Source="{Binding IconSource}"
                           Grid.Column="0"
                           Width="96"
                           Height="96"
                           VerticalAlignment="Center"
                           Visibility="{Binding Editing, Converter={StaticResource visibilityConverter}}"
                           />

                    <TextBlock Text="{Binding Name}" 
                               Grid.Column="1" 
                               Foreground="{Binding Enabled, Converter={StaticResource enabledConverter}}" />

                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>

It gives two compiler errors: the ListBox ContentListBox and InitializeComponent() are not defined. I suspect that the problem has something to do with how the class is split into two partial definitions, and mine is parameterized whereas the generated code is not. How can I get around this?

  • 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-05-18T03:13:04+00:00Added an answer on May 18, 2026 at 3:13 am

    No you can’t use generic types in Silverlight XAML directly.

    But you could familiarize yourself with the MVVM pattern. Your models and viewmodels can easily be generic types, and you can do all your coding there. The XAML views are dumb, have no or few code behind, and only bind to the view models.

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

Sidebar

Related Questions

I have a page which displays a form that a logged-in user can use
I have this ListView that displays a custom user control. The custom user control
I have a user control that I'm building. It's purpose is to display the
I have a user control that is pretty basic. It contains several TextBox controls,
i have a user control that descends from UserControl. When dropped onto the form
I currently have a user control that is used on both an /Address/Edit and
I want to have a User Control that takes a collection of People (property
I have a web user control that contains several other (web user) controls and
I have a view user control that can post form. This control can be
I have a custom user control that contains asp:ValidationSummary . It is placed on

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.