wpf数据绑定:我哪里出错了?请帮忙 [英] wpf data binding: where i am going wrong? please help

查看:54
本文介绍了wpf数据绑定:我哪里出错了?请帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次尝试wpf,并且经过Pete O''Hanlon的大量研究和帮助。我能够达到一定程度。但是在与类绑定之后,当我在类代码中更改时,我仍然无法获得标签的值



我正在使用VS2008框架3.5



i am trying wpf for the first time and with lot of research and help from Pete O''Hanlon. i was able to come to a certain point. but after binding with the class and all i am still not able to get the value to the label when it changes in the code of class

I am using VS2008 framework 3.5

<Window x:Class="Window1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="Avenet Prduct Description Extractor" Height="396.627" Width="588.123" removed="AliceBlue" >
    <Grid Height="341.077" Width="567.721" removed="AliceBlue">

        
        <StackPanel Margin="170.225,226.418,3.143,0" Name="StackPanel1" Height="97.994" VerticalAlignment="Top">
            <Label Height="30.906" Name="lblCrntSt1" Content="{Binding PrdFrstName}" Width="161" BorderThickness="2" BorderBrush="AliceBlue" Background="Red" Foreground="White" FontSize="13"></Label>
            <Label Height="33.633" Name="lblcrntst2" Content="{Binding prdScndName}" Width="161" BorderThickness="2" BorderBrush="AliceBlue" Background="Red" Foreground="White" FontSize="13"></Label>
            <Label Height="29.997" Name="lblcrntst3" Content="{Binding prdLastName}" Width="161" BorderThickness="2" BorderBrush="AliceBlue" Background="Red" Foreground="White" FontSize="13">Label State3</Label>
        </StackPanel>
        <StackPanel Margin="0,62.216,73.348,0" Name="StackPanel2" Height="94.816" VerticalAlignment="Top" removed="Honeydew" HorizontalAlignment="Right" Width="144.43">
            <StackPanel.Resources>
                <Style TargetType="Button">
                    <Setter Property="Margin" Value="0,07,0,0"></Setter>

                </Style>

            </StackPanel.Resources>
            
        
    </Grid>
</Window>







这里是初始化的窗口类






here is the window class where it is initialized

Class Window1

    Dim clsIniti As New ExtractDetails

Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        'clsIniti = New ExtractDetails
        Me.DataContext = clsIniti

        ' Add any initialization after the InitializeComponent() call.

    End Sub
end class









这是我的班级,一切都发生了。这是一个单独的类







here is my class where it all happens. this is a separate class

Public Class ExtractDetails
    Inherits UserControl
    Implements System.ComponentModel.INotifyPropertyChanged

    Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
    
    Private _prdFrstName, _prdScndName, _prdLastName As String
    Private lstPdfDwn As List(Of String) = New List(Of String)
    Dim intPgeLop As Integer = 0
    Dim blnPgeLod As Boolean


#Region "Properties for Passing back the values to form"
 
    Public Property PrdFrstName() As String
        Get
            Return _prdFrstName
        End Get
        Set(ByVal value As String)
            If _prdFrstName <> value Then
                _prdFrstName = value
                OnPropertyChanged("PrdFrstName")
            End If
        End Set
    End Property



    Public Property prdScndName() As String
        Get
            Return _prdScndName
        End Get
        Set(ByVal value As String)
            If _prdScndName <> value Then
                _prdScndName = value
                OnPropertyChanged("prdScndName")
            End If
        End Set
    End Property

    Public Property prdLastName() As String
        Get
            Return _prdLastName
        End Get
        Set(ByVal value As String)
            If _prdLastName <> value Then
                _prdLastName = value
                OnPropertyChanged("prdLastName")
            End If
        End Set
    End Property

	Private Sub OnPropertyChanged(ByVal propertyName As String)
        	RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
    	End Sub

#End Region


 Public Sub suMainStrt(ByVal strFilePath As String)
		PrdFrstName= "http://www.lg.com"

                Call extract(webBrwFrst, strComurl(1))
                webBrwFrst.Dispose()
                webBrwFrst = Nothing
end sub

End Class







我感到困惑。请纠正我。我对这个WPF和MVVM完全不熟悉

提取功能正常工作,我得到了所有细节和所有东西

i在Windows窗体中创建它并且它工作得很好。



这是编辑的男女同校,我可能错过了添加一些东西。但我没有得到任何错误,因为在我的VS2008




I m getting confused. please correct me. i am totally new to this WPF and MVVM
the extract function is working and i am getting all the details and every thing
i created this in windows forms and it is working great.

this is edited coed and i might have missed adding something. but i am not getting any errors as of such in my VS2008

推荐答案

我犯了一个愚蠢的错误,即创建该类对象两次并访问属性中没有值的对象。大错。

所以只创建了一个实例,它就像魅力一样。
i did a silly mistake of creating that class objects twice and accessing object with no values in the properties. big blunder.
so created only one instance and it is working like charm.


这篇关于wpf数据绑定:我哪里出错了?请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆