SORU
4 Kasım 2008, Salı


databind Kaynak WPF Tarayıcı özelliği

Herkes databind için nasıl biliyor mu .Kaynak WPF Tarayıcı özelliği ( 3.5SP1 )? Ben bir liste görünümü istediğim için küçük bir Tarayıcı üzerinde solda, içerik sağ databind kaynağının her Tarayıcı ile URI her nesne bağlı liste öğesi.

Bu kavram bir kanıtı olarak şimdiye kadar ne var, ama "<WebBrowser Source="{Binding Path=WebAddress}"" derleme değil.

<DataTemplate x:Key="dealerLocatorLayout" DataType="DealerLocatorAddress">                
    <StackPanel Orientation="Horizontal">
         <!--Web Control Here-->
        <WebBrowser Source="{Binding Path=WebAddress}"
            ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
            ScrollViewer.VerticalScrollBarVisibility="Disabled" 
            Width="300"
            Height="200"
            />
        <StackPanel Orientation="Vertical">
            <StackPanel Orientation="Horizontal">
                <Label Content="{Binding Path=CompanyName}" FontWeight="Bold" Foreground="Blue" />
                <TextBox Text="{Binding Path=DisplayName}" FontWeight="Bold" />
            </StackPanel>
            <TextBox Text="{Binding Path=Street[0]}" />
            <TextBox Text="{Binding Path=Street[1]}" />
            <TextBox Text="{Binding Path=PhoneNumber}"/>
            <TextBox Text="{Binding Path=FaxNumber}"/>
            <TextBox Text="{Binding Path=Email}"/>
            <TextBox Text="{Binding Path=WebAddress}"/>
        </StackPanel>
    </StackPanel>
</DataTemplate>

CEVAP
5 Kasım 2008, ÇARŞAMBA


Sorun WebBrowser.Source bir DependencyProperty değildir. Bir geçici çözüm, bazı AttachedProperty büyü bu özelliği etkinleştirmek için kullanmak olacaktır.

public static class WebBrowserUtility
{
    public static readonly DependencyProperty BindableSourceProperty =
        DependencyProperty.RegisterAttached("BindableSource", typeof(string), typeof(WebBrowserUtility), new UIPropertyMetadata(null, BindableSourcePropertyChanged));

    public static string GetBindableSource(DependencyObject obj)
    {
        return (string) obj.GetValue(BindableSourceProperty);
    }

    public static void SetBindableSource(DependencyObject obj, string value)
    {
        obj.SetValue(BindableSourceProperty, value);
    }

    public static void BindableSourcePropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
    {
        WebBrowser browser = o as WebBrowser;
        if (browser != null)
        {
            string uri = e.NewValue as string;
            browser.Source = !String.IsNullOrEmpty(uri) ? new Uri(uri) : null;
        }
    }

}

Xaml sonra yapın:

<WebBrowser ns:WebBrowserUtility.BindableSource="{Binding WebAddress}"
    ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
    ScrollViewer.VerticalScrollBarVisibility="Disabled" 
    Width="300"
    Height="200" />

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Emotional Trancer

    Emotional Tr

    4 Mart 2010
  • Mismag822 - The Card Trick Teacher

    Mismag822 -

    18 EKİM 2008
  • Tina Chen

    Tina Chen

    26 Mayıs 2012