Windows Phone 7 - TextBlock文本绑定到ViewModel不返回anythinig [英] Windows Phone 7 - TextBlock Text binding to ViewModel not returning anythinig

查看:113
本文介绍了Windows Phone 7 - TextBlock文本绑定到ViewModel不返回anythinig的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个视图模型,并且listbox绑定到ObervableCollection,但是我正在使用一个temp url的文本框不会绑定和返回数据。我没有在编译或运行时收到任何错误。



ViewModel:

  public class HomepageModel:INotifyPropertyChanged 
{
public TextBlock bgrImg {get; set;}
public ObservableCollection< MenuItem>菜单{get; private set;}

public HomepageModel()
{
this.menu = new ObservableCollection< MenuItem>();
}

public void Load()
{
bgrImg = new TextBlock();
bgrImg.Text =/Windows7MobileClient;component/Images/Desert.jpg;
// bgrImg =;
menu.Add(new MenuItem(Feed,));
menu.Add(new MenuItem(Messages,));
menu.Add(new MenuItem(Media,));
menu.Add(new MenuItem(Favorites,));
menu.Add(new MenuItem(Freinds,));
}

public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if(null!= handler)
{
handler(this,new PropertyChangedEventArgs(propertyName));
}
}
}

Homepage.xaml

 < controls:PanoramaItem Header =menu> 
< Grid>
< TextBlock Text ={Binding bgrImg}/>
< ListBox x:Name =FirstListBoxMargin =0,0,-12,0ItemsSource ={Binding menu}MouseLeftButtonUp =FirstListBox_MouseLeftButtonUp>
< ListBox.ItemTemplate>
< DataTemplate>
< StackPanel Margin =0,0,0,17Width =432>
< TextBlock Text ={Binding label}TextWrapping =WrapStyle ={StaticResource PhoneTextExtraLargeStyle}/>
< / StackPanel>
< / DataTemplate>
< /ListBox.ItemTemplate>
< / ListBox>
< / Grid>
< / controls:PanoramaItem>

我最终想要使用全景背景图片的字符串。对不起,如果这看起来真的很明显。



Chris

解决方案

你需要在您的设置器中调用NotifyPropertyChanged()以获取要绑定的项目。


I have built a view model and the listbox binds to the ObervableCollection, but a textbox I am using for a temp url wont bind and return data. I am not getting any errors either on compile or run

ViewModel:

public class HomepageModel:INotifyPropertyChanged
{
    public TextBlock bgrImg{get;set;}
    public ObservableCollection<MenuItem> menu {get; private set;}

    public HomepageModel()
    {
        this.menu = new ObservableCollection<MenuItem>();
    }

    public void Load()
    {
        bgrImg = new TextBlock();
        bgrImg.Text = "/Windows7MobileClient;component/Images/Desert.jpg";
        //bgrImg = ;
        menu.Add(new MenuItem("Feed",""));
        menu.Add(new MenuItem("Messages",""));
        menu.Add(new MenuItem("Media",""));
        menu.Add(new MenuItem("Favourites",""));
        menu.Add(new MenuItem("Freinds",""));
    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(String propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (null != handler)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

Homepage.xaml

<controls:PanoramaItem Header="menu">
            <Grid>
                <TextBlock Text="{Binding bgrImg}"/>
                <ListBox x:Name="FirstListBox" Margin="0,0,-12,0" ItemsSource="{Binding menu}" MouseLeftButtonUp="FirstListBox_MouseLeftButtonUp" >
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Margin="0,0,0,17" Width="432">
                                <TextBlock Text="{Binding label}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </Grid>
        </controls:PanoramaItem>

I eventual want to use the string for the panorama background image. Sorry if this seems realy obviously simply.

Chris

解决方案

You need to call NotifyPropertyChanged() in your setters for the items you wish to bind to.

这篇关于Windows Phone 7 - TextBlock文本绑定到ViewModel不返回anythinig的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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