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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:12:16+00:00 2026-05-24T04:12:16+00:00

I have a windows phone 7 app with some xaml that looks like: <Grid

  • 0

I have a windows phone 7 app with some xaml that looks like:

<Grid x:Name="ContentGrid" Grid.Row="1">
    <ItemsControl x:Name="MyView" ItemTemplate="{StaticResource MyInner}"/>
</Grid>

The item template here looks like:

<DataTemplate x:Key="MyInner">
    <ItemsControl ItemsSource="{Binding}" ItemTemplate="{StaticResource MyInner_Item}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
</DataTemplate>

And finally, the MyInner_Item template looks like:

<DataTemplate x:Key="MyInner_Item">
    <Button x:Name="MyButton">
        <Button.Template>
            <ControlTemplate>
                <Border HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="myborder">

                    <Image Source="{Binding Path=ImageUri}" Width="{Binding Path=Width}" Height="{Binding Path=Height}" Stretch="Fill" />
                </Border>
            </ControlTemplate>
        </Button.Template>
    </Button>
</DataTemplate>

So, it’s an ItemsControl, which contains an ItemsControl, which contains buttons. This essentially creates a 2D array of buttons.

What I want to do is add an event handler to the Click event of the buttons.

Here’s the catch: the code that sits behind this is written in F#. I can’t, to the best of my knowledge, specify my event handler in the XAML, as F# doesn’t talk to WPF in any nice way. So I need to add my event handler(s) manually in code.

Is there an easy way of doing this?

Currently, I have some F# which looks like:

let myView : ItemsControl = this?MyView
do myView.ItemsSource <- viewModel.BoardData 

Here, the BoardData is a list of lists.

I was wondering if it’s possible to loop through the controls in the ItemsControl, to add my event handlers? I’m having a bit of trouble doing this though. For example, in the following:

let container = myView.ItemContainerGenerator.ContainerFromItem(myView.Items.[0])

…sets container to null. In fact, all the methods I’ve tried from myView.ItemContainerGenerator returns null.

So, how should I go about attaching my event handler, so that I can respond to the buttons being clicked?

  • 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-24T04:12:17+00:00Added an answer on May 24, 2026 at 4:12 am

    I have not done any Windows 7 Phone development, but I have done plenty of XAML + Silverlight development with C# and now I’m getting into doing some F# development. The approach I would take is by not using event handler’s at all. Since you are using a button, make a class that derives from ICommand and add that type as a public property on your ViewModel so you could bind it to the Command property of the button. The benefits of using the ICommand interface over event handlers is that you could also have a condition on when the button is enabled to do the action.

    Also, take notice that when you are doing binding expressions within (i.e. ItemTemplate) items in an ItemsControl control, the scope of what properties you can bind to are reduced to the properties of the current item. So all of the properties of the ViewModel are out of scope, unless you specify it fully i.e. <Button Command={Binding Source=ViewModel, Path=Property1.Property2.etc} />. Let me know if this helped.

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

Sidebar

Related Questions

I have a Windows Phone 7.5/Silverlight app. I have some code that I duplicate
I have some trigger in my Windows Phone 7 Silverlight app such as <Grid
I have a Windows Phone 7 app that has a space in the name.
I have a windows phone 7.1 app that tries to get data from a
I have a listbox for a Windows Phone 7 app that displays info parsed
My app is a windows phone 7 application. In that i have created a
I have a windows phone app that allows the user to interact with it.
I have a Windows Phone application I am developing that needs to persist some
I have some C# code in a Windows Phone app... WebRequest wrq = WebRequest.CreateHttp(http://bing.com);
I have a Silverlight Windows Phone 7 app that pulls data from a public

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.