我在Windows 10通用应用程序中使用带有SemanticZoom的GridView。这是我的简单测试代码:
#ifndef TENSOR_HPP
#define TENSOR_HPP
#include <vector>
#include <array>
#include <boost/numeric/odeint.hpp>
namespace nex {
template <size_t...> struct seq {};
template <size_t N, size_t... Is> struct gen_seq : gen_seq<N-1, N-1, Is...> {};
template <size_t... Is> struct gen_seq<0, Is...> { using type = seq<Is...>; };
template<typename T, typename S>
class tensor;
template<typename T, size_t... Is>
class tensor<T, seq<Is...>>
{
typedef std::vector<T> vector;
public:
// constructor
tensor ();
tensor (decltype(Is)...);
// iterators
using iterator = typename vector::iterator;
using const_iterator = typename vector::const_iterator;
iterator begin()
{ return m_v.begin(); }
const_iterator begin() const
{ return m_v.begin(); }
iterator end()
{ return m_v.end(); }
const_iterator end() const
{ return m_v.end(); }
// resizing
size_t size() const;
void resize( const tensor<T, seq<Is...>>& );
// operators
const T& operator() (decltype(Is)...) const;
T& operator() (decltype(Is)...);
private:
// helper functions
template <size_t I>
auto index(const std::array<size_t, sizeof...(Is)>& a) const
-> typename std::enable_if<I == 0, size_t>::type
{
return a[I];
}
template <size_t I>
auto index(const std::array<size_t, sizeof...(Is)>& a) const
-> typename std::enable_if<I != 0, size_t>::type
{
return index<I-1>(a) * s[I] + a[I];
}
size_t mult(size_t N)
{
return N;
}
template <typename... S>
size_t mult(size_t N, S... Ns)
{
return N * mult(Ns...);
}
vector m_v;
std::array<size_t, sizeof...(Is)> s;
}; // class tensor
template<typename T, size_t... Is>
tensor<T, seq<Is...>> :: tensor ()
: m_v(), s{ { 0 } }
{}
template<typename T, size_t... Is>
tensor<T, seq<Is...>> :: tensor (decltype(Is)... size)
: m_v( mult( size... ) ), s{ { size... } }
{}
template<typename T, size_t... Is>
size_t tensor<T, seq<Is...>> :: size () const
{ return m_v.size(); }
template<typename T, size_t... Is>
void tensor<T, seq<Is...>> :: resize (const tensor<T, seq<Is...>> &x)
{
m_v.resize( x.size() );
s = x.s;
}
template<typename T, size_t... Is>
const T& tensor<T, seq<Is...>> :: operator() (decltype(Is)... n) const
{ return m_v.at(index<sizeof...(Is)-1>( { { n... } } ) ); }
template<typename T, size_t... Is>
T& tensor<T, seq<Is...>> :: operator() (decltype(Is)... n)
{ return m_v.at(index<sizeof...(Is)-1>( { { n... } } ) ); }
} // namespace nex
namespace boost { namespace numeric { namespace odeint {
template<typename T, size_t... Is>
struct is_resizeable< nex::tensor<T, nex::seq<Is...>> >
{
typedef boost::true_type type;
static const bool value = type::value;
};
template<typename T, size_t... Is>
struct resize_impl< nex::tensor<T, nex::seq<Is...>>, nex::tensor<T, nex::seq<Is...>> >
{
typedef nex::tensor<T, nex::seq<Is...>> state_type;
static void resize( state_type &x1 , const state_type &x2 )
{
x1.resize(x2);
}
};
} // namespace odeint
} // namespace numeric
} // namespace boost
template <typename T, std::size_t N>
using tensor = nex::tensor<T, typename nex::gen_seq<N>::type>;
#endif // TENSOR_HPP
如果我更改页面大小,则显示垂直滚动。但我需要水平滚动。我尝试添加我的GridView
<SemanticZoom.ZoomedInView>
<GridView x:Name="Nums" >
<GridViewItem>1</GridViewItem>
<GridViewItem>2</GridViewItem>
<GridViewItem>3</GridViewItem>
...
<GridViewItem>299</GridViewItem>
<GridViewItem>300</GridViewItem>
</GridView>
</SemanticZoom.ZoomedInView>
<SemanticZoom.ZoomedOutView>
<ListView>
<ListViewItem x:Name="Group1">1-100</ListViewItem>
<ListViewItem x:Name="Group2">101-200</ListViewItem>
<ListViewItem x:Name="Group3">201-300</ListViewItem>
</ListView>
</SemanticZoom.ZoomedOutView>
</SemanticZoom>
但这不起作用。如何在GridView中添加水平滚动?
答案 0 :(得分:2)
我决定了我的问题。这个工作代码:
<SemanticZoom.ZoomedInView >
<GridView ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollMode="Auto">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Vertical" MaximumRowsOrColumns="3"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
....
</SemanticZoom>