ViewMakerで生成するWPF/Silverlightコントロール(10)Hyperlink編
外部文書との連携が必要な場合などに利用されるHyperlinkをViewMakerでもサポートしています。
Hyperlinkコントロール
WPFではHyperlinkを利用していますが、SilverlightではHyperlinkButtonを利用しいています。いずれも標準でふくまれていて、URIアドレスが指定されたstring型のにバインドします。ナビゲーションURI(NavigateUri)を別途指定することもできます。なお、WPFではHyperlinkがPageに配置されていないとNavigateUriで指定されたページに移動しませんが、ViewMakerは自動的にプロセス起動するようにしています。なお、指定したコマンドを動かすことも可能です。
ViewMakerで指定可能なHyperlinkの項目は以下の通りです。
WPFサンプルイメージとXAMLコード
<Label> <Hyperlink Name="Hyperlink1" NavigateUri="{Binding Path=Hyperlink1,Mode=OneWay}" vg:RequestNavigateBehavior.IsEnabled="true" xmlns:vg="clr-namespace:ViewMaker.Core.Wpf;assembly=ViewMaker.Core"> <TextBlock Text="{Binding Path=Hyperlink1,Mode=OneWay}" /> </Hyperlink> </Label> <Label> <Hyperlink Name="Hyperlink2" NavigateUri="{Binding Path=Hyperlink2Url,Mode=OneWay}" vg:RequestNavigateBehavior.IsEnabled="true" xmlns:vg="clr-namespace:ViewMaker.Core.Wpf;assembly=ViewMaker.Core"> <TextBlock Text="{Binding Path=Hyperlink2,Mode=OneWay}" /> </Hyperlink> </Label> <Label Width="200" Foreground="Blue" Background="Azure" HorizontalAlignment="Left"> <Hyperlink Name="Hyperlink3" Command="{Binding Path=Hyperlink3Command,Mode=OneWay}"> <TextBlock Text="{Binding Path=Hyperlink3,Mode=OneWay}" /> </Hyperlink> </Label>
SilverlightサンプルイメージとXAMLコード
<HyperlinkButton Name="Hyperlink1" Content="{Binding Path=Hyperlink1,Mode=OneWay}" NavigateUri="{Binding Path=Hyperlink1,Mode=OneWay}" /> <HyperlinkButton Name="Hyperlink2" Content="{Binding Path=Hyperlink2,Mode=OneWay}" NavigateUri="{Binding Path=Hyperlink2Url,Mode=OneWay}" /> <HyperlinkButton Name="Hyperlink3" Content="{Binding Path=Hyperlink3,Mode=OneWay}" Command="{Binding Path=Hyperlink3Command,Mode=OneWay}" Width="200" Foreground="Blue" Background="Azure" HorizontalAlignment="Left" />
ViewModelコード
[View(ViewControlType.StackPanel)] [ViewProperty(StackPanelViewControl.Properties.HeaderPosition, LayoutHeaderPosition.Hidden)] public class HyperlinkSample : ViewModel { [View(ViewControlType.Hyperlink)] public string Hyperlink1 { get; set; } [View(ViewControlType.Hyperlink)] [ViewProperty(HyperlinkViewControl.Properties.NavigateUri, "Hyperlink2Url")] public string Hyperlink2 { get; set; } [Browsable(false)] public string Hyperlink2Url { get; set; } [View(ViewControlType.Hyperlink)] [ViewProperty(HyperlinkViewControl.Properties.Command, "Hyperlink3Command")] [ViewProperty(HyperlinkViewControl.Properties.Width, 200)] [ViewProperty(HyperlinkViewControl.Properties.Foreground, "Blue")] [ViewProperty(HyperlinkViewControl.Properties.Background, "Azure")] public string Hyperlink3 { get; set; } [Browsable(false)] public ICommand Hyperlink3Command { get { return CreateCommand(() => this.ShowMessage("Hyperlink3")); } } public HyperlinkSample() { Hyperlink1 = "http://viewmaker.codeplex.com/"; Hyperlink2 = "ViewMaker"; Hyperlink2Url = "http://viewmaker.codeplex.com/"; Hyperlink3 = "Message"; } }