1

我有一个列表视图,我正在通过代码填充标签。当用户单击我要处理 MouseDown 事件的标签时,它不会触发。预览鼠标按下确实会触发。

我知道这里有一些关于路由/冒泡事件的内容,我猜这会解决我遇到的问题,这是我尚未掌握的概念。

我不能使用预览事件,因为它不包含我需要的对象(直到第二次单击标签才分配标签信息,所以我假设我需要 MouseDown 而不是预览)

珍惜你的时间。

XAML

 <telerik:RadTabItem x:Name="Media" Header="Media" Height="22" Width="100">
                <Grid x:Name="ListboxMedia">


                    <ListView x:Name="ListViewImages" HorizontalAlignment="Left" Height="303" Margin="697,10,0,0" VerticalAlignment="Top" Width="178" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" IsTabStop="True" TabIndex="3" MouseDown="ListViewImages_MouseDown" PreviewMouseDown="ListViewImages_PreviewMouseDown">
                        <ListView.View>
                            <GridView>
                                <GridViewColumn x:Name="ListViewImageColumn" Header="Images" Width="178" />
                            </GridView>
                        </ListView.View>
                    </ListView>

                    <Button x:Name="BtnUpload" Content="Upload" Height="24" Margin="809,318,38,0" VerticalAlignment="Top" Click="BtnUpload_Click"/>
                    <Button x:Name="BtnDownload" Content="Download" Height="24" Margin="728,318,109,0" VerticalAlignment="Top"/>
                    <Image x:Name="ImageViewPort" HorizontalAlignment="Left" Height="293" Margin="21,20,0,0" VerticalAlignment="Top" Width="581"/>
                </Grid>

            </telerik:RadTabItem>

将标签填充到 ListViewImages 中的方法

 void PopulateMedia()
        {
            var collectImages = new Media().CollectMediaForAsset(_assetId);

            int i = 1;

            foreach (var collectImage in collectImages)
            {
                var label = new Label();
                label.Tag = collectImage.FileName;
                label.Content = "Image" + i.ToString();
                ListViewImages.Items.Add(label);                
                i++;
            }
        }

处理程序

 private void ListViewImages_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Debug.WriteLine("Clicked Down"); //does not work


        }

        private void ListViewImages_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Debug.WriteLine("Clicked Preview"); //works


        }
4

1 回答 1

-1

Used selection changed event instead

于 2013-03-02T20:39:02.327 回答