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

  • Home
  • SEARCH
  • 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 4080738
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:58:07+00:00 2026-05-20T17:58:07+00:00

I am starting with WPF development on a touch device. Although .NET and WPF

  • 0

I am starting with WPF development on a touch device. Although .NET and WPF seem to be an amazing technology, I am somewhat lost.

I am developing a generic control. I defined an UserControl which contains a Grid, some buttons and a SurfaceListBox. In the actual C#-code I am handling events and add new elements to the list box by manipulation the listItems-Attribute. This works fine so far.

Now I would like to change the style of the list items – I would like to make their background transparent if they are not selected, and completely white if they are. Unfortunately the following piece of code simply does not work. It just sets the background color of the list item text to white, but not the whole item.

Update: Now it works!

<UserControl x:Class="SGEditor.MyControl"
         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" 
         xmlns:my="http://schemas.microsoft.com/surface/2008" UseLayoutRounding="True">
<UserControl.Resources>
    <Style TargetType="{x:Type ListBoxItem}" x:Key="ContainerStyle">
        <Setter Property="Background" Value="Transparent" />
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Background" Value="White" />
            </Trigger>
        </Style.Triggers>
    </Style>
</UserControl.Resources>

<Grid>        
    <my:SurfaceListBox Width="300" Height="300" />
</Grid>
</UserControl>

Thank you!

Hans

  • 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-20T17:58:08+00:00Added an answer on May 20, 2026 at 5:58 pm

    I don’t know exactly how to do what you want to do, but I’m pretty sure you can’t reassign a static system value like you’re trying to do in x:Key. That’s just a name you use to reference the resource later in the xaml, like MyBackgroundColor or whatever.

    I think what you need to do is something with triggers in the style for your control that set the appropriate properties for the elements you want to change. Hopefully someone else will shed more light on that, since I rarely do that fancy stuff. =)

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

Sidebar

Related Questions

I am starting a WPF project, which will be fairly complicated in complexity and
So I'm just starting out with WPF, and I'm really annoyed by the fact
My company is just starting to look at using WPF for migrating all of
I'm reading WPF Recipes in C# 2008: http://www.apress.com/book/view/9781430210849 and starting on the third recipe
any good recommendations for databinding. i am starting to look into WPF more and
Starting from ASP.NET MVC Preview 3, HTML.Button ( and other related HTML controls) are
I'm starting to learn WPF and currently use Visual Studio Express 2010 at home.
I'm just starting out with WPF and I'm trying to layout a UI. I
I am starting to work with images in WPF and I am using the
I'm just starting to work with Silverlight (no WPF experience either) and am having

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.