桌面应用程序中的流体布局包装面板/ VariableSizedWrapGrid? [英] Fluid layout wrap panel / VariableSizedWrapGrid in desktop applications?

查看:86
本文介绍了桌面应用程序中的流体布局包装面板/ VariableSizedWrapGrid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在桌面应用程序中使用,非常好。它没有任何用于适当绑定的依赖项属性,但是添加它们并不困难。我还在使用MahApps的最新的Metro库(与可通过nuget获得的Metro库不同)用于其图块控制,但这不是必需的。



这就是它的最终样子:





以下是该代码的首字母缩写:



MainWindow.xaml:

 < Window x:Class = TileExample.MainWindow 
xmlns = http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x = http://schemas.microsoft.com/winfx/2006/xaml
xmlns: Masonry = clr-namespace:MasonryLibrary; assembly = MasonryLibrary
Title =标题
Loaded = Window_Loaded
Height = 400
Width = 600> ;
< Grid>
< Masonry:Masonry x:Name = ui_masonry
VerticalAlignment = Top
Animation = False>
< / Masonry:Masonry>
< / Grid>
< / Window>

MainWindow.xaml.cs:

  private void Window_Loaded(object sender,RoutedEventArgs e){
for(int i = 0; i< 15; i ++){
var tile = new Tile() ;
tile.Header = i.ToString();
ui_masonry.Add(tile);
}
}

Tile.xaml:

 < UserControl x:Class = TileExample.Tile 
xmlns = http://schemas.microsoft.com/winfx/2006/ xaml / presentation
xmlns:x = http://schemas.microsoft.com/winfx/2006/xaml
xmlns:mc = http://schemas.openxmlformats.org/markup-兼容性/ 2006
xmlns:d = http://schemas.microsoft.com/expression/blend/2008
xmlns:Controls = clr-namespace:MahApps.Metro.Controls; assembly = MahApps.Metro
mc:Ignorable = d
Width = 140
Height = 140
Name = ui_ctrl
d:DesignHeight = 300
d:DesignWidth = 300>
< UserControl.Resources>
< ResourceDictionary>
< ResourceDictionary.MergedDictionaries>
< ResourceDictionary Source = pack:// application:,,, / MahApps.Metro; component / Styles / Colours.xaml />
< ResourceDictionary Source = pack:// application:,,, / MahApps.Metro; component / Styles / Fonts.xaml />
< ResourceDictionary Source = pack:// application:,, // MahApps.Metro; component / Styles / Controls.xaml />
< ResourceDictionary Source = pack:// application:,, // MahApps.Metro; component / Styles / Controls.AnimatedSingleRowTabControl.xaml />
< ResourceDictionary Source = pack:// application:,,, // MahApps.Metro.Resources; component / Icons.xaml />
< ResourceDictionary Source = pack:// application:,,, / MahApps.Metro; component / Styles / Accents / Blue.xaml />
< ResourceDictionary Source = pack:// application:,,, // MahApps.Metro; component / Styles / Accents / BaseLight.xaml />
< ResourceDictionary Source = pack:// application:,,, / MahApps.Metro; component / Styles / FlatSlider.xaml />
< ResourceDictionary Source = / Resources / Effects / Animations.xaml />
< /ResourceDictionary.MergedDictionaries>
< / ResourceDictionary>
< /UserControl.Resources>
< Controls:Tile Title =未使用
x:Name = ui_tile
Click = Tile_Click>
< ItemsControl x:Name = ui_tile_content>
< / ItemsControl>
< / Controls:Tile>
< / UserControl>

Tile.xaml.cs:

 公共部分类Tile:UserControl {

public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register( Header,
typeof(string),
typeof(瓷砖));
public Tile(){
InitializeComponent();
}

private void Tile_Click(object sender,RoutedEventArgs e){
//您的动画代码在这里...
//我利用了自己的一些动画为此,只需
// //将图块扩展到其宽度和高度的两倍
}

公共字符串Header {
get {return(string)GetValue(HeaderProperty ); }
set {
SetValue(HeaderProperty,value);
ui_tile.Title =值;
}
}
}

我在动画中添加了一些动画磁贴,以便当用户单击它们时它们会扩展。砌体库偶尔出现故障时的表现也不错,但是我对结果感到非常满意。我最终添加了一些UI逻辑,以仅允许一次扩展一个图块。


Is it possible to use the VariableSizedWrapGrid control in desktop apps (i.e. Windows 7 WPF applications)? Presently this control only seems available in WinRT, Windows 8, Windows Phone, etc. If it's possible, how? Otherwise, what option would I have to get the same sort of functionality?

For those who aren't familiar with the concept, it would be similar to a WrapPanel, however elements would fill open spaces in the panel rather than spill over onto the next row, like so (see also Masonry for jQuery):

解决方案

I ended up utilizing Lizzaran's WPF-Masonry library, which is pretty nice. It didn't come with any dependency properties for proper binding, but it wouldn't be difficult to add them. I'm also using MahApps' latest Metro library (different than the one that's available through nuget) for their tile control, but that's not necessary.

Here's what it ended up looking like:

Here is the brunt of the code:

MainWindow.xaml:

<Window x:Class="TileExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Masonry="clr-namespace:MasonryLibrary;assembly=MasonryLibrary"
        Title="Tiles"
        Loaded="Window_Loaded"
        Height="400"
        Width="600">
  <Grid>
    <Masonry:Masonry x:Name="ui_masonry"
                     VerticalAlignment="Top"
                     Animation="False">
    </Masonry:Masonry>
  </Grid>
</Window>

MainWindow.xaml.cs:

private void Window_Loaded(object sender, RoutedEventArgs e) {
  for (int i = 0; i < 15; i++) {
    var tile = new Tile();
    tile.Header = i.ToString();
    ui_masonry.Add(tile);
  }
}

Tile.xaml:

<UserControl x:Class="TileExample.Tile"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
             mc:Ignorable="d"
             Width="140"
             Height="140"
             Name="ui_ctrl"
             d:DesignHeight="300"
             d:DesignWidth="300">
  <UserControl.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedSingleRowTabControl.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro.Resources;component/Icons.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/FlatSlider.xaml" />
        <ResourceDictionary Source="/Resources/Effects/Animations.xaml" />
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </UserControl.Resources>
  <Controls:Tile Title="Not Used"
                 x:Name="ui_tile"
                 Click="Tile_Click">
    <ItemsControl x:Name="ui_tile_content">
    </ItemsControl>
  </Controls:Tile>
</UserControl>

Tile.xaml.cs:

  public partial class Tile : UserControl {

    public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register("Header",
                                                                                       typeof(string),
                                                                                       typeof(Tile));
    public Tile() {
      InitializeComponent();
    }

    private void Tile_Click(object sender, RoutedEventArgs e) {
      //Your animation code here...
      //I utilized some animations from my own library for this that simply
      //expands the tile to twice its width and height
    }

    public string Header {
      get { return (string)GetValue(HeaderProperty); }
      set {
        SetValue(HeaderProperty, value);
        ui_tile.Title = value;
      }
    }
  }

I added some animations to my tiles so that they expand when a user clicks on them. The Masonry library performs pretty well with an occasional glitch, but I'm pretty happy with how it turned out. I eventually added some UI logic to only allow for one tile to be expanded at time.

这篇关于桌面应用程序中的流体布局包装面板/ VariableSizedWrapGrid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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