开发者

How to select UI Elements within a custom data template for a listbox item in Silverlight

Hello all I have a usercontrol that I have defined as a data template. What I trying to do is have the results returned in a wrap panel and have each result returned in a tile format. I have this all working and the resutls are returned properly. However I have within the data template items that I would like the user to click upon. (scrollviewer to scroll data, buttons to click and text to select)/ Currently when you click on the selected item the item is selected but it is as if everything inside the listbox item is locked ( not selectable).

I'd appreciate any suggestions as to what I am missing here. Listed below is my code for the user controls and how I reference the wrap panel from app.xaml

SearchResultTileControl.xaml

<UserControl x:Class="UI.Search.Controls.SearchResultTileControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:dts="clr-namespace:UI.Search.Commands"
         xmlns:formatter="clr-namespace:UI.Search.Commands"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:qr="clr-namespace:UI.Search.Controls.tiles"
         d:DesignHeight="300"
         d:DesignWidth="400"
         mc:Ignorable="d">

<Grid x:Name="LayoutRoot"  >
    <ListBox x:Name="ResultListBox"
             HorizontalAlignment="Stretch"
             Background="{x:Null}"
             BorderThickness="0"
             HorizontalContentAlignment="Stretch"
             ItemsPanel="{StaticResource ResultsItemsControlPanelTemplate}"
             ItemContainerStyle="{StaticResource ListBoxItemStyle1}"
             ItemsSource="{Binding SearchResults[0].Results}"
             ScrollViewer.HorizontalScrollBarVisibility="Disabled">
        <ListBox.ItemTemplate>

            <DataTemplate>
                <formatter:TypeTemplateSelector Content="{Binding}" HorizontalContentAlignment="Stretch">   
                    <!--  Person Template  -->
                    <formatter:TypeTemplateSelector.PersonTemplate>
                        <DataTemplate>
                            <qr:ucTilePerson />
                        </DataTemplate>
                    </formatter:TypeTemplateSelector.PersonTemplate>

                    <!--  Incident Template  -->
                    <formatter:TypeTemplateSelector.IncidentTemplate>
                        <DataTemplate>
                            <qr:ucTileIncident />
                        </DataTemplate>
                    </formatter:TypeTemplateSelector.IncidentTemplate>

                </formatter:TypeTemplateSelector>

            </DataTemplate>
        </ListBox.ItemTemplate>

    </ListBox>

</Grid>

Within the Usercontrol ucTilePerson.xaml I have the template setup as:

<UserControl x:Class="UI.Search.Controls.tiles.ucTilePerson"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:formatter="clr-namespace:UI.Search.Commands"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
         Width="300"
    开发者_如何学C     Height="250"
         d:DesignHeight="250"
         d:DesignWidth="300"
         IsHitTestVisible="False"
         mc:Ignorable="d">
<UserControl.Resources>
    <formatter:TileHighlightConverter x:Key="FormatConverter" />
</UserControl.Resources>
<Grid x:Name="PersonLayoutRoot">
    <Rectangle Style="{StaticResource TileBackground}" />
    <ScrollViewer Margin="5" BorderBrush="{x:Null}">
        <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <StackPanel Margin="0,0,0,2" Orientation="Horizontal">
                <StackPanel>
                    <Image Width="48"
                           Height="48"
                           Source="/Images/search/person.png" />
                    <TextBlock Style="{StaticResource TileRelevance}" Text="{Binding Relevance}" />
                </StackPanel>
                <StackPanel>
                    <HyperlinkButton Content="{Binding Type}" Style="{StaticResource TypeHyperlinkButton}" />
                    <TextBox Margin="0,0,0,2"
                             Style="{StaticResource TileTextBox}"
                             Text="{Binding Content[AgencyName]}"
                             TextWrapping="Wrap" />
                </StackPanel>
            </StackPanel>

            <toolkit:WrapPanel Margin="0,0,0,2">
                <TextBlock Style="{StaticResource TileLabel}" Text="Name" />
                <TextBox Margin="0,0,3,0"
                         Style="{StaticResource TileTextBox}"
                         Text="{Binding Content[lastname]}" />
                <TextBox Margin="0,0,3,0"
                         Style="{StaticResource TileTextBox}"
                         Text="{Binding Content[firstname]}" />
                <TextBox Style="{StaticResource TileTextBox}" Text="{Binding Content[middlename]}" />
            </toolkit:WrapPanel>
            <Border Style="{StaticResource TileBorder}">
                <toolkit:WrapPanel Orientation="Horizontal">
                    <StackPanel Style="{StaticResource TileVerticalStackPanel}">
                        <TextBlock Style="{StaticResource TileLabel}" Text="Race" />
                        <TextBox Style="{StaticResource TileTextBox}" Text="{Binding Content[race]}" />
                    </StackPanel>
                    <StackPanel Style="{StaticResource TileVerticalStackPanel}">
                        <TextBlock Style="{StaticResource TileLabel}" Text="Sex" />
                        <TextBox Style="{StaticResource TileTextBox}" Text="{Binding Content[sex]}" />
                    </StackPanel>
                    <StackPanel Style="{StaticResource TileVerticalStackPanel}">
                        <TextBlock Style="{StaticResource TileLabel}" Text="DOB" />
                        <TextBox Style="{StaticResource TileTextBox}" Text="{Binding Content[dob]}" />
                    </StackPanel>
                </toolkit:WrapPanel>
            </Border>
            <Border Style="{StaticResource TileBorder}">
                <toolkit:WrapPanel Orientation="Horizontal">
                    <StackPanel Style="{StaticResource TileVerticalStackPanel}">
                        <TextBlock Style="{StaticResource TileLabel}" Text="Involvement" />
                        <TextBox Style="{StaticResource TileTextBox}" Text="{Binding Content[involvementtype]}" />
                    </StackPanel>
                    <StackPanel Style="{StaticResource TileVerticalStackPanel}">
                        <TextBlock Style="{StaticResource TileLabel}" Text="Associated Event" />
                        <TextBox Style="{StaticResource TileTextBox}" Text="{Binding Content[0].EventAssociation}" />
                        <HyperlinkButton Content="{Binding Content[0].EventID}" Style="{StaticResource TileResultLink}" />
                    </StackPanel>

                </toolkit:WrapPanel>
            </Border>
            <Border Style="{StaticResource TileBorder}">
                <ContentControl Width="256"
                                Margin="0,0,6,0"
                                BorderThickness="0"
                                Content="{Binding HitContext,
                                                  Converter={StaticResource FormatConverter}}"
                                FontSize="11" />
            </Border>

        </StackPanel>
    </ScrollViewer>
</Grid>

And then I set reference to the wrap panel used in the listboxt ItemsPanel in my app.xaml

<ItemsPanelTemplate x:Key="ResultsItemsControlPanelTemplate">
        <toolkit:WrapPanel/>
    </ItemsPanelTemplate>

I suspect this is something in the Listbox styles that may be preventing this but I am not positive. Thanks again for any suggestions,

Cheers


Discovered the issue. Within the usercontrol (ucTilePerson) I had IsHitTestVisible set to false. Since it was set at the user control level all elements inherited this property which is why I was getting the effect of not being able to raise any mouse events on anything.

No idea why I set that there other than it was late in the day.

Cheers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜