我试图弄清楚如何通过多个类正确传递属性.我知道我可以INotifyPropertyChanged在每个类中实现并监听属性的更改,但这似乎是相当多的不必要的代码.
情况:
我有一个类(让我们称之为Class1)有两个依赖属性:FilterStatement(String)和Filter(Filter类).设置语句会影响过滤器,反之亦然.
然而,语句和过滤器之间的转换逻辑不是位于Class1,而是位于Class3- 它Class1不直接知道.在两者之间Class2只需要通过变化.(你可以想象1到3级的视图模型,模型和存储库,虽然在实际情况下这并不完全匹配).
public class Class1
{
public static readonly DependencyProperty FilterProperty = DependencyProperty.Register(
"Filter",
typeof(Filter),
typeof(Class1),
new FrameworkPropertyMetadata(null));
public static readonly DependencyProperty FilterStatementProperty = DependencyProperty.Register(
"FilterStatement",
typeof(String),
typeof(Class1),
new FrameworkPropertyMetadata(null));
public Filter Filter
{
get { return (Filter)GetValue(FilterProperty); }
set { SetValue(FilterProperty, value); }
}
public string FilterStatement
{
get { return (string)GetValue(FilterStatementProperty); }
set { SetValue(FilterStatementProperty, value); }
}
public …Run Code Online (Sandbox Code Playgroud) 我创建了一个引擎,它提供了一个ui组件作为单元格.相应的gem(criteria_operator-ui_component)在lib文件夹中几乎不包含任何代码,因为要使单元格正常运行,我必须在资源路径中工作.gem的基本文件如下所示:
require 'criteria_operator/ui_component/engine'
require 'cells/rails'
module CriteriaOperator
module UiComponent
# Your code goes here...
end
end
Run Code Online (Sandbox Code Playgroud)
引擎不包含太多:
module CriteriaOperator
module UiComponent
class Engine < ::Rails::Engine
require 'jquery-rails'
require 'criteria_operator'
isolate_namespace CriteriaOperator::UiComponent
end
end
end
Run Code Online (Sandbox Code Playgroud)
对我来说,看起来宝石甚至不知道细胞,但据我所知,我不允许在lib文件夹之外包含任何东西.此外,在项目中测试虚拟应用程序中的单元格工作正常.
现在我在一个真正的Rails应用程序中使用这个引擎.在gemfile中,我包括以下内容:
gem 'criteria_operator'
gem 'cells' # i added these three, because `bundler list` didn't show me
gem 'cells-rails' # `cells-rails` and `cells-erb` even though they are listed
gem 'cells-erb' # as dependencies for the engine
gem 'criteria_operator-ui_component'
Run Code Online (Sandbox Code Playgroud)
我登上了路线
mount CriteriaOperator::UiComponent::Engine => …Run Code Online (Sandbox Code Playgroud) 只是一个小问题,我没有找到具体的答案所以我猜这可能会更快在这里问.
编译器拒绝以下代码,并出现以下错误:
不兼容类型'动态数组'和'数组字符串'
TMailInfo = record
FileName,
MailAdresse,
MailBCC,
MailCC,
MailBetreff: string;
MailText,
Anhang: array of string;
MailAcknowledge,
MailTXT: Boolean
end;
class function TEMail.SendOutlookCOMMail(aFileName, aMailAdresse,
aMailBCC, aMailCC, aMailBetreff: string;
aMailText, aAnhang: array of string;
const aMailAcknowledge, aMailTXT: Boolean): Boolean;
var
mailInfo: TMailInfo;
begin
...
mailInfo.MailBetreff := aMailBetreff; // these two lines cause the error
mailInfo.MailText := aMailText;
...
end;
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?两者都是字符串数组,所以我不明白为什么一个似乎是动态的.
有没有办法在不使用外部资源的情况下将两个字母的国家代码转换为可读的国家代码?
例如DE -> Germany,AD -> Andorra
如果我可以选择目标语言或使用系统语言会很好,因为我想用德语.
我目前正在尝试提高构建机器的性能。标准构建在每次提交 (svn) 后排队,大约需要 40 分钟。如果提交时已经有一个排队的构建,我们不会添加另一个。所以每个构建都有 1+ 次提交的更改。由于提交可能没有对所有项目进行更改,因此可以通过仅重建受影响的项目来减少构建时间。
我不知道如何找出需要构建哪些项目。有没有办法可靠地找出触发构建的提交所影响的内容?我首先考虑浏览 .dpr 文件并检查引用文件中的更改,但并非所有文件都列在那里,因为我们还使用搜索路径...
如果没有,是否至少有一种方法可以查明项目是否肯定不会受到影响?老实说,我不太知道如何解决这个问题......
我知道有多个问题与此标题相似,但我没有发现任何与我的问题相似的问题。如果已经有解决方案,因此我的问题是重复的,我很抱歉 - 我只是没有找到它,并不是我没有搜索。
我正在使用 ActiveAdmin 和 ActiveSkin 主题。我的模型有一个表单Agent,我想在其中使用嵌套表单来建立has_many关系。我在部分创建了这段代码:
<%= semantic_form_for [@agent], builder: ActiveAdmin::FormBuilder do |f| %>
<%= f.semantic_errors %>
<%= f.inputs 'General Information' do %>
<%= f.input :name %>
<%= f.input :description %>
<% end %>
<%= f.inputs 'Capture Columns' do %>
<%= f.has_many :capture_columns, new_record: 'Add Column' do |column| %>
<%= column.input :column_name %>
<%= column.input :column_datatype %>
<% end %>
<% end %>
<%= f.actions do %>
<%= f.action :submit %>
<li class="cancel"><%= link_to …Run Code Online (Sandbox Code Playgroud) 我在使用 MahApps.Metro 的简单 ContextMenu 遇到了一个奇怪的问题,没有任何额外的样式。将光标移动到文本顶部或稍微围绕文本移动时,没有问题。但是当它移得更远时,仍然在 ContextMenu 边界内,Cursor 不再位于 MenuItem 之上。除了关闭 ContextMenu 之外,现在单击也不会导致任何操作。
<ContextMenu ItemsSource="{Binding ContextItems}">
<ContextMenu.ItemTemplate>
<DataTemplate>
<MenuItem Header="{Binding Text}" Command="{Binding Command}"/>
</DataTemplate>
</ContextMenu.ItemTemplate>
</ContextMenu>
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?为什么 MenuItem 不使用可用空间?
我正在尝试浏览一个对象列表,但我只想提供由我的对象实现的接口.
我有两种情况:只是在内部列举我的列表(这不是一个大问题,我可以只使用对象而不是接口)和一个属性.
ITemplate = interface
...
end;
TTemplate = class (TInterfacedObject, ITemplate)
...
end;
TMyClass = class
strict private
FTemplates: TObjectList<TTemplate>;
function GetTemplates: IEnumerable<ITemplate>;
...
public
property Templates: IEnumerable<ITemplate> read GetTemplates;
...
procedure TMyClass.LoopTroughInternally;
var
template: ITemplate;
begin
for template in FTemplates do // isn't working, of course
foobar(template);
end;
function TMyClass.GetTemplates: IEnumerable<ITemplate>;
begin
// dunno what to do here...
end;
Run Code Online (Sandbox Code Playgroud)
有没有办法提供这个枚举器而不实现特定的IEnumerable?
我正在尝试使用 ItemContainerStyleSelector 根据定义行的对象的类型在数据网格中显示不同的行样式(ItemsSource 是IGridItems的集合,存在GridItem并且GridSeparator应该获得不同的样式)。我的问题是,SelectStyle我的 StyleSelector 从未被调用过。现在我发现(这里)问题可能是继承的样式(MahApps Metro 库重新定义了所有标准控件的默认样式),它可能已经设置了 ItemContainerStyle。
所以现在我的问题是:有没有办法仍然使用我的 StyleSelector,以便我将继承的样式作为所选样式的基础?如果没有,我如何根据对象类型为某些行实现不同的样式?
编辑:
手动设置 ItemContainerStylenull没有效果,SelectStyle我的 StyleSelector 仍然没有被调用。
EDIT2:
因为我System.Windows.Data Error: 24 : Both 'ItemContainerStyle' and 'ItemContainerStyleSelector' are set; 'ItemContainerStyleSelector' will be ignored.不像 Grx70 那样问,所以我认为 ItemContainerStyle 不是问题,就像我最初认为的那样。
jstreet 指出,它与 MahApps.Metro 相关,但是......(见他的评论)
我目前的实现:
<DataGrid ItemsSource="{Binding Items}" ItemContainerStyleSelector="{StaticResource StyleSelector}">
Run Code Online (Sandbox Code Playgroud)
Syle 选择器:
public class GridRowStyleSelector : StyleSelector
{
private readonly ResourceDictionary _dictionary;
public GridRowStyleSelector()
{
_dictionary = new ResourceDictionary …Run Code Online (Sandbox Code Playgroud) delphi ×4
c# ×3
delphi-xe5 ×2
wpf ×2
activeadmin ×1
build ×1
delphi-xe6 ×1
enumeration ×1
forms ×1
interface ×1
localization ×1
mvvm ×1
properties ×1
rails-cells ×1
svn ×1