首页 \ 问答 \ 自定义网格在WPF网格中调整大小(Custom grid resize in WPF grid)

自定义网格在WPF网格中调整大小(Custom grid resize in WPF grid)

我正在使用这个 DataGrid (它只不过是一个包含更多东西的DataGrid )。 我希望能够垂直调整网格的大小,而不是其行或列的大小。 在我附加的图像中,您可以看到窗口的第一行和底部之间有一个巨大的空白区域。 我需要的是当鼠标悬停在网格顶部(网格标题顶角的某个位置)时,有一个调整大小的光标。 调整大小时,网格中元素的大小不需要更改,只需要更改网格的总高度。

此外,网格应始终的最大高度仅为“添加事件”按钮。

换句话说,我希望用户能够从这个:

在此处输入图像描述

对此:

在此处输入图像描述


I am using this DataGrid (which is nothing more than a DataGrid with more stuff). I would like to be able to resize vertically the size of the grid, not the size of its rows or columns. In the image I attached you can a see a huge blank space between the first row and the bottom of the window. What I need is that when the mouse hovers by the top of the grid (somewhere in the top corner of the grid's header) to have a resize cursor. When resizing, the size of the elements in the grid don't need to change, just the total height of the grid.

Also, the maximum height the grid should always be is just bellow the "Add event" buttom.

In other words, I want the user to be able to go from this:

enter image description here

To this:

enter image description here


原文:https://stackoverflow.com/questions/16598237
更新时间:2024-04-04 06:04

最满意答案

attr_accessorattr_accessible ,尽管几乎完全相同的拼写,但绝对是不同的方法。

attr_accessor ,一个本机Ruby方法,它为类的实例定义一个getter和一个setter方法:

class User
  attr_accessor :password
end

u = User.new
u.password = "secret"
u.password # => "secret"

attr_accessible是Rails带来的一种方法,它的意思是将模型的已有属性“列入白名单”。 attr_accessible中枚举的属性可以稍后通过模型属性的质量分配进行更改(而其他属性将被列入黑名单且不可更改):

class Account < ActiveRecord::Base
  # First, you define 2 attributes: "password" and "created_at"
  attr_accessor :password
  attr_accessor :created_at

  # Now you say that you want "password" attribute
  # to be changeable via mass-assignment, while making
  # "created_at" to be non-changeable via mass-assignment
  attr_accessible :password
end

a = Account.new

# Perform mass-assignment (which is usually done when you update
# your model using the attributes submitted via a web form)
a.update_attributes(:password => "secret", :created_at => Time.now)

a.password # => "secret"
# "password" is changed

a.created_at # => nil
# "created_at" remains not changed

您可以使用attr_accessible来防止“外人”干扰模型的某些属性(例如,您不希望您的“Account.superadmin”属性可以通过简单的表单提交进行更改,这将是一个糟糕的安全问题)。

请注意,您可以单独更改属性,无论其“白名单/黑名单”状态如何:

a.created_at = Time.now

a.created_at # => 2012-09-16 10:03:14

attr_accessor and attr_accessible, despite almost identical spelling, are absolutely different methods.

attr_accessor, a native Ruby method which defines a getter and a setter method for the instance of the class:

class User
  attr_accessor :password
end

u = User.new
u.password = "secret"
u.password # => "secret"

attr_accessible is a method brought by Rails and it is meant to "whitelist" already existing attributes of a model. Attributes enumerated in attr_accessible can be later changed via mass-assignment of model attributes (while other attributes will be blacklisted and not changeable):

class Account < ActiveRecord::Base
  # First, you define 2 attributes: "password" and "created_at"
  attr_accessor :password
  attr_accessor :created_at

  # Now you say that you want "password" attribute
  # to be changeable via mass-assignment, while making
  # "created_at" to be non-changeable via mass-assignment
  attr_accessible :password
end

a = Account.new

# Perform mass-assignment (which is usually done when you update
# your model using the attributes submitted via a web form)
a.update_attributes(:password => "secret", :created_at => Time.now)

a.password # => "secret"
# "password" is changed

a.created_at # => nil
# "created_at" remains not changed

You use attr_accessible to prevent meddling with some attributes of your models by "outsiders" (e.g. you wouldn't want your "Account.superadmin" attribute to be changeable via a simple form submission, which would be a bad security issue).

Note, that you can change the attributes individually, regardless of their "whitelisting/blacklisting" status:

a.created_at = Time.now

a.created_at # => 2012-09-16 10:03:14

相关问答

更多
  • attr_accessor是一个ruby方法,使一个吸气剂和一个设定器。 attr_accessible是一个Rails方法,允许您将值传递给大量分配: new(attrs)或update_attributes(attrs) 。 这是一个质量分配: Order.new({ :type => 'Corn', :quantity => 6 }) 您可以想象,订单也可能有折扣代码,例如:price_off。 如果你没有标记:price_off作为attr_accessible,你可以阻止恶意代码能够这样做: O ...
  • Rails 4现在使用强参数 。 保护属性现在在控制器中完成。 这是一个例子: class PeopleController < ApplicationController def create Person.create(person_params) end private def person_params params.require(:person).permit(:name, :age) end end 不需要在模型中设置attr_accessible 。 ...
  • attr_accessor和attr_accessible ,尽管几乎完全相同的拼写,但绝对是不同的方法。 attr_accessor ,一个本机Ruby方法,它为类的实例定义一个getter和一个setter方法: class User attr_accessor :password end u = User.new u.password = "secret" u.password # => "secret" attr_accessible是Rails带来的一种方法,它的意思是将模型的已有属性“列 ...
  • attr_accessor可以用于您不想直接存储在数据库中的值,并且只能在对象的生命周期内存在(例如密码)。 attr_reader可以作为几种替代方法之一来做这样的事情: def instance_value "my value" end attr_accessor can be used for values you don't want to store in the database directly and that will only exist for the life of the o ...
  • 如果用“in rails”表示“activerecord models”,那么你的猜测是正确的:瞬态属性。 这是一个例子(有点做作): class User < ActiveRecord::Base attr_accessor :is_admin validate_presence_of :name, :shipping_address, :billing_address, unless: :is_admin end 通过常规流程(注册页面)创建的用户将拒绝保存,除非您提供所有信息。 但是创建管 ...
  • attr_protected 对这些属性的质量分配将被忽略,分配给他们可以使用直接写入器方法。 这是为了保护敏感属性不被恶意用户篡改URL或表单所覆盖。 attr_protected Mass-assignment to these attributes will simply be ignored, to assign to them you can use direct writer methods. This is meant to protect sensitive attributes from ...
  • 使用attr_accessor与Active Record无关。 我在这篇文章中讨论它是如何工作的, 这也与AR有关。 现在,AR 做了什么,它是基于数据库模型自动创建自己的“访问者”方法(例如x/x= )。 这些自动创建的方法实际上只是用于代理内部AR工作的存根。 关键是, attr_accessor (自动)包装简单的实例变量访问,而AR(自动)创建的方法包装AR魔术。 这两个操作是互斥的。 因为attr_accessor没有“链接”到AR魔法,所以它可以用于创建不持久的瞬态字段:AR不知道或不关心实例 ...
  • 如果使用attr_accessible ,则模型将阻止对未包含在attr_accessible列表中的列进行批量分配。 受影响的方法是mass assignment的方法,如new , create , update_attributes , attributes=等。所有其他函数都可以工作,甚至单个赋值如下: @model_object.column_not_listed_in_attr_accessible_list = "Saved" @model_object.column_not_listed_i ...
  • 尝试这个: dynamic_attributes = {test: 1, test2: 2, test3: 3} #object could be self depending on the context object.instance_eval(class << self; self; end) }.class_eval do dynamic_attributes.each do |attr, value| define_method(attr){ value } define_me ...
  • 基本上,因为在rails表单中,您可以向表单添加任何字段。 如果用户向表单添加新参数并将其提交给您的服务器,它可能会给您带来很大的问题。 像这样: 你的控制器: LineItem.create(params[:line_item) 如果这是你的控制器,用户可以通过javascript或通过控制台编辑在chrome上插入一个新的文本字段,他可以修改受保护的字段。 这就是为什么我们使用attr_accessible只允许defioned字段。 因此,不在attr_accessible中的attr_access ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)