Silverlight 中 ListBoxItem 中的访问按钮

发布于 2024-09-07 05:35:48 字数 824 浏览 1 评论 0原文

嘿大家。我是 Silverlight 新手,想要访问属于 ListBoxItem 的按钮控件。但是,我不太确定该怎么做。我的 XAML 是:

<DataTemplate x:Key="ItemTemplate2">
            <Grid Height="51">
                <TextBlock x:Name="tbName" Text="{Binding Property1}" Margin="0,0,98,0" d:LayoutOverrides="Height" Grid.ColumnSpan="2" HorizontalAlignment="Left" VerticalAlignment="Center"/>
                <Button x:Name="btnInfo"  HorizontalAlignment="Right" Margin="0,-11,0,0" Width="87" Height="54" VerticalAlignment="Top" Background="#FF8EC1D2" BorderBrush="#FF8EC1D2" BorderThickness="0">
                    <Image Source="../Images/btnNameImage.png" Stretch="None"/>                 
                </Button>
            </Grid>
        </DataTemplate>

如何从代码隐藏访问“btnInfo”?

感谢您的帮助

Hey everyone. I'm new to Silverlight and would like to access a button control that is part of a ListBoxItem. However, I'm not quite sure how to do this. My XAML is:

<DataTemplate x:Key="ItemTemplate2">
            <Grid Height="51">
                <TextBlock x:Name="tbName" Text="{Binding Property1}" Margin="0,0,98,0" d:LayoutOverrides="Height" Grid.ColumnSpan="2" HorizontalAlignment="Left" VerticalAlignment="Center"/>
                <Button x:Name="btnInfo"  HorizontalAlignment="Right" Margin="0,-11,0,0" Width="87" Height="54" VerticalAlignment="Top" Background="#FF8EC1D2" BorderBrush="#FF8EC1D2" BorderThickness="0">
                    <Image Source="../Images/btnNameImage.png" Stretch="None"/>                 
                </Button>
            </Grid>
        </DataTemplate>

How can I access the "btnInfo" from the code-behind?

Thanks for any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

§普罗旺斯的薰衣草 2024-09-14 05:35:48

您将无法直接从后面的代码访问它,但您应该能够通过向其注册事件来执行您想要的操作。将 Loaded 事件添加到按钮,然后在代码隐藏中定义相应的方法。

protected btninfo_Loaded(object sender, EventArgs e)
{
    Button btnInfo = (Button) sender;
    //do whatever you need to do
}

显然你可以做同样的事情来处理点击事件或任何你想要的。

you wont be able to access it directly from code behind, but you should be able to do what you want by registering an event with it. Add a Loaded event to the button then in your codebehind define the corresponding method.

protected btninfo_Loaded(object sender, EventArgs e)
{
    Button btnInfo = (Button) sender;
    //do whatever you need to do
}

obviously you can do the same thing to handle click events or whatever you want.

三生殊途 2024-09-14 05:35:48

这并不能直接回答您以编程方式访问数据模板的问题,但是绑定怎么样?

This doesn't directly answer your question of programatically accessing a data template, but how about Binding?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文