my xaml code is:
<FlipView x:Name="flipView">
<FlipView.ItemTemplate>
<DataTemplate>
<ScrollViewer>
<Image Source="Assets/1.png" Width="{Binding ContentWidth}" Height="{Binding ContentHeight}"/>
</ScrollViewer>
</DataTemplate>
</FlipView.ItemTemplate>
<FlipView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Background="Transparent" Orientation="Horizontal"/>
</ItemsPanelTemplate>
</FlipView.ItemsPanel>
</FlipView>
my c++ code in "....xaml.cpp" file is :
Platform::Collections::Vector<PageModel^>^ m_items = ref new Platform::Collections::Vector<PageModel^>();
m_items->Append(ref new PageModel());
m_items->Append(ref new PageModel());
m_items->Append(ref new PageModel());
flipView->ItemsSource = m_items;
my PageModel class code is :
ref class PageModel sealed : public Windows::UI::Xaml::Data::ICustomPropertyProvider,
public Windows::UI::Xaml::Data::INotifyPropertyChanged
{
internal:
PageModel(){ w = 10; h = 10;}
public:
~PageModel(){}
virtual Windows::UI::Xaml::Data::ICustomProperty^ GetCustomProperty(Platform::String^ name) override
{
if (name == "ContentWidth")
{
return ref new BindableProperty(
"Platform::Object",
name,
ref new PropertyGetter(this, &PageModel::GetContentWidth),
nullptr
);
}
else if (name == "ContentHeight")
{
return ref new BindableProperty(
"Platform::Object",
name,
ref new PropertyGetter(this, &PageModel::GetContentHeight),
nullptr
);
}
return nullptr;
}
virtual Windows::UI::Xaml::Data::ICustomProperty^ GetIndexedProperty(
Platform::String^ name, Windows::UI::Xaml::Interop::TypeName type) override
{
throw ref new Platform::NotImplementedException();
}
virtual Platform::String^ GetStringRepresentation() override
{
throw ref new Platform::NotImplementedException();
}
virtual property Windows::UI::Xaml::Interop::TypeName Type
{
Windows::UI::Xaml::Interop::TypeName get();
}
TypeName Type::get()
{
TypeName typeName;
typeName.Kind = TypeKind::Custom;
typeName.Name = "Object";
return typeName;
}
virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ PropertyChanged ;
Platform::Object^ GetContentWidth(_In_ Platform::Object^ object)
{
return Windows::Foundation::PropertyValue::CreateInt32(w);
}
Platform::Object^ GetContentHeight(_In_ Platform::Object^ object)
{
return Windows::Foundation::PropertyValue::CreateInt32(h);
}
void UpdateContent()
{
w += 10;
h += 10;
PropertyChanged(this, ref new PropertyChangedEventArgs("ContentWidth"));
PropertyChanged(this, ref new PropertyChangedEventArgs("ContentHeight"));
}
private:
int w;
int h;
};
------
INotifyPropertyChanged:Notifies clients that a property value has changed.
PageModel is used with gridview or listview, the application runs right, but PageModel is used with flipview, the application can't run right.
who can tell me why?
thanks first.
-- King Star.
winRT