7 wpf hyperlink caliburn.micro
嗨我有问题绑定方法对"LabelLink"控件的点击事件.我使用pseudeo LabelLink控件,我想大家都知道这个解决方案有textBox和超链接.
这是我的代码:
<TextBlock Margin="10,12,10,4">
<Hyperlink Name="RegLink"
NavigateUri="http://registracia.azet.sk/"
Micro:Message.Attach="[Event Click]=[Action OpenDefaultBrowser(NavigateUri)]"
FontSize="12">Registrácia</Hyperlink>
Run Code Online (Sandbox Code Playgroud)
问题是我只能在框架元素上绑定方法.
我得到这个编译错误:
Cannot attach type "ActionMessage" to type "Hyperlink". Instances of type "ActionMessage" can only be attached to objects of type "FrameworkElement".
Run Code Online (Sandbox Code Playgroud)
我用谷歌搜索,芽没有找到任何合适的解决方案.
谢谢你的建议.
我尝试使用textBlock或Label控件制作一个假的linkLabel但它们没有click事件处理程序.
Edg*_*dez 10
我调整了@Rick对Caliburn.Micro的回答
在TestView.xaml中
<Grid>
<Grid.Resources>
<Style x:Key="HyperlinkButton" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<ContentPresenter/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Button Style="{StaticResource HyperlinkButton}" Focusable="False"
cal:Message.Attach="[Action NavigateTo('http://www.stackoverflow.org')]">
<TextBlock>
<Hyperlink Focusable="False">www.stackoverflow.com</Hyperlink>
</TextBlock>
</Button>
</Grid>
Run Code Online (Sandbox Code Playgroud)
在TestViewModel.cs中
public void NavigateTo(string url)
{
Process.Start(new ProcessStartInfo(url));
}
Run Code Online (Sandbox Code Playgroud)
我在我的应用程序中使用这种方式,它的工作原理.希望它能帮到你.
您可以将其嵌入Hyperlink到Button看起来不像按钮的按钮中,以便获取在以下位置Click发生的事件FrameworkElement:
<Grid>
<Grid.Resources>
<Style x:Key="HyperlinkButton" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<ContentPresenter/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<StackPanel>
<Button Name="button1" Style="{StaticResource HyperlinkButton}" Click="Button_Click" Focusable="False">
<TextBlock>
<Hyperlink NavigateUri="http://www.stackoverflow.com" Focusable="False">
StackOverflow
</Hyperlink>
</TextBlock>
</Button>
</StackPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud)
也许您可以将此技术应用于Caliburn.Micro.