财产变更事件UWP无效

时间:2017-06-19 12:24:28

标签: c# .net uwp uwp-xaml

关于这个问题有一些问题,我看了很多,但我似乎仍然出错了! 我找到的这个论坛上的所有例子都是针对一个属性的,我有一些/列表。

在我的Models文件夹中,我有一个名为Locations的类

public class Locations: INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged = delegate { };
    locationManager loc = new locationManager();



    private void NotifyPropertyChanged(List<String> PropertyChangedList)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(Convert.ToString(PropertyChangedList)));
        }

    }

    public string locationColumn { get; set; }
    public int locationRow { get; set; }
    public string locationColumnImage { get; set; }
    public string baleInformation { get; set; }
    public int numberOfBales { get; set; }
    private List<String> columnList;
    public List<String> ColumnList
    {
        get
        {
            return columnList;
        }
        set
        {
            if (value != columnList)
            {
                columnList = value;
                NotifyPropertyChanged(ColumnList);
            }


        }
    }
}

然后在同一个.cs文件中我有另一个类(是的不是很好,仍然会把它全部拿掉)

public class locationManager
{   

    #region GetLocations
    public  List<Locations> getLocations()
    {

        Locations storeLocations = new Locations();

        //represents db value of how many items in a particlar location
        var baleCol = buildColumnList();          
        var location = new List<Locations>();

        location.Add(new Locations { locationColumn = "A", locationColumnImage = "Assets/A.jpg", numberOfBales = baleCol.Where(a => a != null && a.StartsWith("A")).Count() });
        location.Add(new Locations { locationColumn = "B", locationColumnImage = "Assets/B.jpg", numberOfBales = baleCol.Where(a => a != null && a.StartsWith("B")).Count() });
        location.Add(new Locations { locationColumn = "C", locationColumnImage = "Assets/c.jpg", numberOfBales = baleCol.Where(a => a != null && a.StartsWith("C")).Count() });
        location.Add(new Locations { locationColumn = "D", locationColumnImage = "Assets/D.jpg", numberOfBales = baleCol.Where(a => a != null && a.StartsWith("D")).Count() });
        location.Add(new Locations { locationColumn = "E", locationColumnImage = "Assets/E.jpg", numberOfBales = baleCol.Where(a => a != null && a.StartsWith("E")).Count() });
        location.Add(new Locations { locationColumn = "F", locationColumnImage = "Assets/F.jpg", numberOfBales = baleCol.Where(a => a != null && a.StartsWith("F")).Count() });
        location.Add(new Locations { locationColumn = "G", locationColumnImage = "Assets/G.jpg", numberOfBales = baleCol.Where(a => a != null && a.StartsWith("G")).Count() });
        location.Add(new Locations { locationColumn = "H", locationColumnImage = "Assets/h.jpg", numberOfBales = baleCol.Where(a => a != null && a.StartsWith("H")).Count() });
        location.Add(new Locations { locationColumn = "I", locationColumnImage = "Assets/I.jpg", numberOfBales = baleCol.Where(a => a != null && a.StartsWith("I")).Count() });
        location.Add(new Locations { locationColumn = "J", locationColumnImage = "Assets/J.jpg", numberOfBales = baleCol.Where(a => a != null && a.StartsWith("J")).Count() });
        location.Add(new Locations { locationColumn = "K", locationColumnImage = "Assets/K.jpg", numberOfBales = baleCol.Where(a => a != null && a.StartsWith("K")).Count() });
    return location;
    }
}

car baleCol等于的buildColumnList();方法只是一个创建Letters / Bumber组合A1或B15类型事物列表的方法。此数据将在稍后阶段从数据库中提取,因此该方法将替换为Linq。

在我的MainPage.xaml中,我有以下列方式绑定的控件

<GridView ItemsSource="{x:Bind location, Mode=OneWay}" Margin="-5,0,5,0">
    <GridView.ItemTemplate>
        <DataTemplate  x:Name="columnTemplate" x:DataType="data:Locations">
            <StackPanel x:Name="columnStack">
                <Image Width="100" Source="{x:Bind locationColumnImage}"/>
                <TextBlock FontSize ="16" Text ="{x:Bind numberOfBales}" HorizontalAlignment="Center"/>                    
            </StackPanel>
        </DataTemplate>
    </GridView.ItemTemplate>
</GridView>

然后MainPage.xaml.cs有此

private List<Locations> location;
Locations baleLocations = new Locations();
locationManager manager = new locationManager();
int Count = 0; 
public MainPage()
{

    this.InitializeComponent();
    location = manager.getLocations();

}

所以从我读过的内容来看,我认为我的问题可能出在绑定/数据上下文中。在MainPage.xaml中,我将gridview ItemSource声明为x:绑定位置,然后在MainPage.xaml.cs中我将位置列为Locations类型(具有属性的类)我将其设置为不同类中的方法LocationManager类&#39; getLocations方法

所以在表单加载时它很好我得到了我需要的数据,但我想要实现的是找到更新网格只包含与我想要找到的相关的项目。所以网格需要更新,这就是我遇到问题的地方。在这一点上,唯一会改变的是columnList属性,因为我使用它来获取A1,B15,C24

背景:

它是一个以行/列格式存储库存的存储工具,因此A1 B2等在初始加载时显示所有可能的列位置,其中包含与该列关联的项目数,而不管行。 如果我们正在寻找水,那么在其中一行中有水的列应位于网格中......这是更新/属性更改应该发生的地方。

0 个答案:

没有答案