English 中文(简体)
2. 采购MV型卡车 服从观点的观点
原标题:Getting MVVM ViewModel to bind to the View

我有以下法典(改写的物体名称,这样一夫一妻/pel倒的错误被忽视)。

public class ViewModel
{
    ViewModelSource m_vSource;

    public ViewModel(IViewModelSource source)
    {
        m_vSource= source;
        m_vSource.ItemArrived += new Action<Item>(m_vSource_ItemArrived);
    }

    void m_vSource_ItemArrived(Item obj)
    {
        Title = obj.Title;
        Subitems = obj.items;
        Description = obj.Description;
    }

    public void GetFeed(string serviceUrl)
    {
        m_vFeedSource.GetFeed(serviceUrl);
    }

    public string Title { get; set; }
    public IEnumerable<Subitems> Subitems { get; set; }
    public string Description { get; set; }
 }

这里是我用手法写的。

ViewModel m_vViewModel;

public MainPage()
{
    InitializeComponent();

    m_vViewModel = new ViewModel(new ViewModelSource());
    this.Loaded += new RoutedEventHandler(MainPage_Loaded);

    this.DataContext = m_vViewModel;
}

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    m_vViewModel.GetItems("http://www.myserviceurl.com");
}

最后,这里是我xaml所看的样本。

<!--TitleGrid is the name of the application and page title-->
<Grid x:Name="TitleGrid" Grid.Row="0">
    <TextBlock Text="My Super Title" x:Name="textBlockPageTitle" Style="{StaticResource PhoneTextPageTitle1Style}"/>
    <TextBlock Text="{Binding Path=Title}" x:Name="textBlockListTitle" Style="{StaticResource PhoneTextPageTitle2Style}"/>
</Grid>

这里是否有任何人错了?

最佳回答

我认为,你的观点是,应当实施“创新”接口:

    public virtual event PropertyChangedEventHandler PropertyChanged;
    protected virtual void RaisePropertyChanged(string propertyName)
    {
        if (this.PropertyChanged != null)
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

之后,贵方的财产希望:

    private title;
    public string Title 
    { 
        get
        {
            return this.title;
        }

        set
        {
            if (this.title!= value)
            {
                this.title= value;
                this.RaisePropertyChanged("Title");
            }
        }
    }

Michael M.

问题回答

我在担任这一职务后,我就算出10名知名人士。

我没有说明执行情况。 如果有人想到这一点,则会表示感谢。





相关问题
Silverlight Rich text box control

Our team decided that we need our own custom Rich text box control for Silverlight app we are developing. We looked at existing controls mentioned at A good rich text control for Silverlight but ...

Silverlight ImageBrush not rendering (with Bing Map Control)

I m trying to add an image to a Pushpin instance from the Silverlight Bing Map Control, but I can t seem to get it to render (the pushpin renders fine). This is probably a general WPF question rather ...

Silverlight OpenFileDialog DoEvents equivalent

I m processing large files after they are selected by the user. My code looks like the following: if (FileDialog.ShowDialog() == true) { // process really big file } This freezes up the UI so ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Silverlight, Updating the UI during processing

I have a simple silverlight multifile upload application, and i want to provide the user with some feedback, right now its only in a test phase and i dont have the webservice. Somehow i cant get the ...

Silverlight 3 - FindName returns null

This looks a bug to me.. Using Silverlight 3 and i have a user control defined in XAML and trying to access the object during runtime returns a null. <Grid> <common:CommonGridEditPanel x:...

silverlight 3 collection binding

Someone please help me understand why this binding does not work... I have a class called SelectionManager with a property called dates which is populated by a WCF service. The property is an ...

热门标签