我正在尝试序列化,我面临着一个抽象类的问题.
我搜索了一个答案,我发现了这个博客.我试过那个和那个工作.
好的,非常好.但请查看该项目的评论:
这种方法似乎隐藏了真正的问题,这是OO设计模式的不准确实现,即工厂模式.
必须更改基类以引用任何新工厂类是弄巧成拙的.
经过一番思考,代码可以更改为任何派生类型可以与抽象类相关联(通过接口的奇迹),并且不需要XmlInclude.
我建议进一步研究工厂模式,这似乎是你试图在这里实现的.
什么是评论者谈论?他有点模糊.有人可以更详细地解释它(举个例子)吗?或者他只是胡说八道?
更新(阅读第一个答案后)
为什么评论员会谈论
工厂模式
和
代码可以更改为任何派生类型可以与抽象类相关联(通过接口的奇迹)
?
他想制作这样的界面吗?
public interface IWorkaround
{
void Method();
}
public class SomeBase : IWorkaround
{
public void Method()
{
// some logic here
}
}
public class SomeConcrete : SomeBase, IWorkaround
{
public new void Method()
{
base.Method();
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个列表框,我想迭代我的Foo对象中的Bars集合.
<ListBox DataContext="{Binding Path=Foo.Bars}" >
<ListBox.Items>
<ListBoxItem>
<ContentControl DataContext="{Binding Path=.}" />
</ListBoxItem>
</ListBox.Items>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
这是我想要使用的datatemplate.
<DataTemplate DataType="{x:Type Bar}">
<Label Content="hello stackoverflow" />
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
如果我窥探( - >使用工具Snoop检查)我的应用程序,我注意到整个 Bars系列绑定到ContentControl,而不是1.
我如何正确绑定,以便对集合的迭代正常?
我有一个带文本框的应用程序,屏幕上文本框的宽度在用户屏幕上必须始终为17.5厘米.
这是我到目前为止所尝试的:
const double centimeter = 17.5; // the width I need
const double inches = centimeter * 0.393700787; // convert centimeter to inches
float dpi = GetDpiX(); // get the dpi. 96 in my case.
var pixels = dpi*inches; // this should give me the amount of pixels
textbox1.Width = Convert.ToInt32(pixels); // set it. Done.
private float GetDpiX()
{
floar returnValue;
Graphics graphics = CreateGraphics();
returnValue = graphics.DpiX;
graphics.Dispose(); // don’t forget to release the unnecessary resources
return returnValue; …Run Code Online (Sandbox Code Playgroud) 我是GreaseMonkey的新手,但我正在尝试制作一个小脚本.
// ==UserScript==
// @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// ==/UserScript==
(function() {
$ = unsafeWindow.jQuery;
alert($); // this gives 'undefined'
}());
Run Code Online (Sandbox Code Playgroud)
为什么警报会给出undefined以及如何解决此问题?
UPDATE
我试过这个:
(function(){
//boilerplate greasemonkey to wait until jQuery is defined...
function GM_wait()
{
alert('ok');
if(typeof unsafeWindow.jQuery == 'undefined')
window.setTimeout(GM_wait,100);
else
unsafeWindow.jQuery(function() { letsJQuery(unsafeWindow.jQuery); });
}
GM_wait();
function letsJQuery($)
{
alert($);
}
})();
Run Code Online (Sandbox Code Playgroud)
但这给了我一个无限循环的ok-alert.好像jQuery根本没有加载.
对于我的生活,我似乎无法使用multibindings绑定到我的viewmodel.net上的所有示例都直接绑定到gui元素,但每当我尝试使用viewmodel对象时,都会抛出异常.
我的问题是,如何在xaml中为多个viewmodel对象添加多绑定?
我需要将上下文菜单的IsEnabled属性绑定到我的viewmodel中的两个整数.以下绑定不起作用,因为它是为GUI组件设计的.如何使用我的整数?
<MenuItem ItemsSource="{Binding MyMenuItem}">
<MenuItem.IsEnabled>
<MultiBinding>
<Binding ElementName="FirstInt" Path="Value" />
<Binding ElementName="SecondInt" Path="Value" />
</MultiBinding>
</MenuItem.IsEnabled>
</MenuItem>
Run Code Online (Sandbox Code Playgroud)
MyMenuItem是CLR对象,带有两个整数FirstInt和SecondInt.
我无法关闭jquery对话框.以下是我的代码.
我有一个名为academic.asp的父页面,它将通过jquery插件打开一个模态对话框.
function openPopupDialog(location, windowTitle, heightValue, widthValue) {
var $dialog = $('#dialogWin').load('submission.asp')
.dialog({
autoOpen: false,
modal: true,
draggable: false,
resizable: false,
title: windowTitle,
width: widthValue,
height: heightValue
});
$dialog.dialog('open');
return false;
}
Run Code Online (Sandbox Code Playgroud)
我的模态窗口将加载页面"submission.asp"
我将在我的模态窗口中使用ajaxForm进行一些提交,如下所示:paperForm =我的表单名称
如何关闭模态并刷新父页面?
提前致谢 :)
我有这张桌子
Run Code Online (Sandbox Code Playgroud)Cream ---------- CHOCALATE GREEN TEST
想要输入这样的选择查询
CHOCALATE,GREEN,TEST
是否可以在运行时修改属性的属性?
假设我有一些课:
public class TheClass
{
[TheAttribute]
public int TheProperty { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
if (someCondition)
{
// disable attribute. Is this possible and how can this be done?
}
Run Code Online (Sandbox Code Playgroud) 我有一个函数示例,它检索json数据并发出警报.
在这个例子中,一切都很顺利:http://jsbin.com/uwupa3/edit
$(document).ready(function(){
var timeService = "http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?";
$.getJSON(timeService, function(data) {
alert(data);
});
});
Run Code Online (Sandbox Code Playgroud)
但在第二个示例中,没有显示警报.为什么?唯一的区别是检索json的服务.json-object对我来说看起来非常有用:http://jsbin.com/uwupa3/2/edit
$(document).ready(function(){
var timeService = "http://json-time.appspot.com/time.json?tz=Europe/Brussels";
$.getJSON(timeService, function(data) {
alert(data);
});
});
Run Code Online (Sandbox Code Playgroud)
我没有JS错误.我也试过这个本地(所以不是在JSbin上,但在我的电脑上有一个htm文件),这也不起作用.
谁能解释我做错了什么?
jquery ×3
wpf ×3
.net ×2
c# ×2
abstract ×1
attributes ×1
data-binding ×1
greasemonkey ×1
json ×1
listbox ×1
listview ×1
modal-dialog ×1
multibinding ×1
mvvm ×1
winforms ×1
xaml ×1