自定义网格在WPF网格中调整大小(Custom grid resize in WPF grid)
我正在使用这个
DataGrid
(它只不过是一个包含更多东西的DataGrid
)。 我希望能够垂直调整网格的大小,而不是其行或列的大小。 在我附加的图像中,您可以看到窗口的第一行和底部之间有一个巨大的空白区域。 我需要的是当鼠标悬停在网格顶部(网格标题顶角的某个位置)时,有一个调整大小的光标。 调整大小时,网格中元素的大小不需要更改,只需要更改网格的总高度。此外,网格应始终的最大高度仅为“添加事件”按钮。
换句话说,我希望用户能够从这个:
对此:
I am using this
DataGrid
(which is nothing more than aDataGrid
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:
To this:
原文:https://stackoverflow.com/questions/16598237
最满意答案
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_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和attr_accessible之间的区别(Difference between attr_accessor and attr_accessible)[2022-12-10]
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 。 ...
-
对rails中的attr_accessor和attr_accessible感到困惑(Confused about attr_accessor and attr_accessible in rails)[2023-01-18]
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' effects)[2023-07-26]
如果使用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 ...