Reputation: 6778
I have a TextBox where a user inputs a uri. This then becomes the NavigateUri property of a hyperlink, allowing the user to click on the link to open the page.
<!-- Input TextBox -->
<TextBox x:Name="linkBox" Width="175" Text="{Binding Path=DocRef, Mode=TwoWay}" />
<!-- Hyperlink -->
<TextBlock>
<Hyperlink DataContext="{Binding ElementName=linkBox}" NavigateUri="{Binding
Path=Text}" RequestNavigate="Hyperlink_RequestNavigate">
<TextBlock DataContext="{Binding ElementName=linkBox}"
Text="{Binding Path=Text}" />
</Hyperlink>
</TextBlock>
This works for inputting the whole (absolute) uri in the TextBox. However, the user wants to only input the 'document.extn' bit of the Uri, and have the application prepend the rest of the resource (ie, the 'http://www.example.com/' bit). How do I set the base part of the uri and append the document reference (preferably in xaml)? I came across Hyperlink's BaseUri property which sounds perfect, but unfortunately is protected, so this doesn't work:
<Hyperlink DataContext="{Binding ElementName=linkBox}"
BaseUri="http://www.example.com/" NavigateUri="{Binding Path=Text}"
RequestNavigate="Hyperlink_RequestNavigate">
Can anybody assist?
Upvotes: 1
Views: 996
Reputation: 43596
You may be able to use MultiBinding
to join the 2 strings you need
<Hyperlink DataContext="{Binding ElementName=linkBox}" RequestNavigate="Hyperlink_RequestNavigate">
<Hyperlink.NavigateUri>
<MultiBinding StringFormat="{}{0}{1}">
<Binding FallbackValue="http://www.example.com/" />
<Binding Path="Text" />
</MultiBinding>
</Hyperlink.NavigateUri>
</Hyperlink>
Upvotes: 2
Reputation: 1122
You can create a Custom Converter using IValueConverter
interface to get the base uri appended uri.
Upvotes: 0