我通过IDictionary将Datagrid绑定到动态数据:http://www.scottlogic.co.uk/blog/colin/2009/04/binding-a-silverlight-datagrid-to-dynamic-data-via-idictionary/comment -page-1 /#评论- 8681
但我不想在xaml中定义任何列(下面是如何在Colin Eberhardt的帖子中完成它
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="Forename" Binding="{Binding Converter={StaticResource RowIndexConverter}, ConverterParameter=Forename}" />
</data:DataGrid.Columns>
Run Code Online (Sandbox Code Playgroud)
所以我编写了以下代码来尝试在后面的代码中执行相同的操作,但代码不会调用RowIndexConverter.必须遗漏一些东西.
码:
// add columns
DataGridTextColumn textColumn = new DataGridTextColumn();
textColumn.Header = "Forename";
Binding bind = new Binding("Forename");
bind.Converter = new RowIndexConverter() ;
bind.ConverterParameter = "Forename";
textColumn.Binding = bind;
_dataGrid.Columns.Add(textColumn);
Run Code Online (Sandbox Code Playgroud)
其余代码(此处为上下文):
// generate some dummy data
Random rand = new Random();
for (int i = 0; i < 200; i++)
{
Row row = new Row();
row["Forename"] = s_names[rand.Next(s_names.Length)];
row["Surname"] = s_surnames[rand.Next(s_surnames.Length)]; …Run Code Online (Sandbox Code Playgroud) 有没有人知道是否有可以将html转换为javascript的工具.
例如:
<div>
</div>
Run Code Online (Sandbox Code Playgroud)
将转换为
aDiv = document.createElement('div');
document.appendChild(aDiv);
Run Code Online (Sandbox Code Playgroud)
等等
我正在为UI组件做一些html模板,并使用MooShell进行原型设计.能够自动生成将构建组件的html的javascript会很棒.
谢谢
可能重复:
将pdf文件转换为jpg asp.net
public class Pdf2Image {
private Image image;
int length;
public int convertPdf2Image(String pdfname) {
File file = new File(pdfname);
RandomAccessFile raf;
try {
raf = new RandomAccessFile(file, "r");
FileChannel channel = raf.getChannel();
ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
PDFFile pdffile = new PDFFile(buf);
// draw the first page to an image
int num = pdffile.getNumPages();
length=num;
for (int i = 0; i <= num; i++) {
PDFPage page = pdffile.getPage(i);
//get the width and height for the …Run Code Online (Sandbox Code Playgroud) 但那些事情似乎不适用于XAML属性:
<MyControl Text={Binding SomeProperty, Converter={StaticResource SomeConverter}, ConverterParameter=Key=Value;/>
Run Code Online (Sandbox Code Playgroud)
我想传递"Key=Value;"给ConverterParameter.
目前我用这种方式解决了问题:
<ItemsControl.ItemsSource>
<Binding Path="LengthVersionList" Converter="{StaticResource LengthVersionListFilterConverter}">
<Binding.ConverterParameter>
<!-- Type=Singular; -->
Type=Singular;
</Binding.ConverterParameter>
</Binding>
</ItemsControl.ItemsSource>
Run Code Online (Sandbox Code Playgroud)
但7行代码用于简单的分配?有没有办法在一行中做到这一点?
编辑
好的,得到3行:
<ItemsControl.ItemsSource>
<Binding Path="LengthVersionList" Converter="{StaticResource LengthVersionListFilterConverter}" ConverterParameter="Type=Plural;" />
</ItemsControl.ItemsSource>
Run Code Online (Sandbox Code Playgroud)
但如果有人有单行解决方案,我会非常高兴.
我需要将包含内存使用量的字符串1048576(例如:(1M))转换为人类可读的版本,反之亦然.
注意:我已经看过这里了: 可重用的库,以获得文件大小的人类可读版本?
在这里(即使它不是python): 如何将人类可读的内存大小转换为字节?
到目前为止没有什么能帮助我,所以我在其他地方看了
我在这里找到了一些可以解决此问题的内容:http://code.google.com/p/pyftpdlib/source/browse/trunk/test/bench.py?specpec = swn984&r = 984#137,或者,对于较短的网址:http://goo.gl/zeJZl
代码:
def bytes2human(n, format="%(value)i%(symbol)s"):
"""
>>> bytes2human(10000)
'9K'
>>> bytes2human(100001221)
'95M'
"""
symbols = ('B', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
prefix = {}
for i, s in enumerate(symbols[1:]):
prefix[s] = 1 << (i+1)*10
for symbol in reversed(symbols[1:]):
if n >= prefix[symbol]:
value = float(n) / prefix[symbol]
return format % locals()
return format % dict(symbol=symbols[0], value=n)
Run Code Online (Sandbox Code Playgroud)
还有一个转换功能(相同的网站):
def human2bytes(s): …Run Code Online (Sandbox Code Playgroud) 我正在尝试检测我通过的表情符号,例如POST(来源不是必需的).
作为一个例子,我正在使用这个表情符号:✊(我希望它是可见的)
它的代码是U+270A U+1F3FE(我使用http://unicode.org/emoji/charts/full-emoji-list.html代码)
现在我用json_encode转换了表情符号,我得到: \u270a\ud83c\udffe
这里唯一相同的部分是270a.\ud83c\udffe是不等于U+1F3FE,即使我把它们加在一起(1B83A)
我怎么从✊到U+270A U+1F3FE例如php?
以下代码定义了映射到数字的名称序列.它旨在获取一个数字并检索特定名称.该类通过确保名称存在于其缓存中来运行,然后通过索引将其返回到其缓存中来返回名称.问题在于:如何在不存储缓存的情况下根据数量计算名称?
该名称可以被认为是基数63,除了始终在基数53的第一个数字.
class NumberToName:
def __generate_name():
def generate_tail(length):
if length > 0:
for char in NumberToName.CHARS:
for extension in generate_tail(length - 1):
yield char + extension
else:
yield ''
for length in itertools.count():
for char in NumberToName.FIRST:
for extension in generate_tail(length):
yield char + extension
FIRST = ''.join(sorted(string.ascii_letters + '_'))
CHARS = ''.join(sorted(string.digits + FIRST))
CACHE = []
NAMES = __generate_name()
@classmethod
def convert(cls, number):
for _ in range(number - len(cls.CACHE) + 1):
cls.CACHE.append(next(cls.NAMES))
return cls.CACHE[number]
def __init__(self, *args, …Run Code Online (Sandbox Code Playgroud) 我想在我的页面中设置一个Date字段
|hours| h |minutes|
Run Code Online (Sandbox Code Playgroud)
小时和分钟在分开的inputText中.
豆有这个日期
import java.util.Date;
...
private Date myDate;
...
Run Code Online (Sandbox Code Playgroud)
而页面是
<h:form>
...
<h:inputText id="myDateHours" maxlength="2" value="#{myBean.myDate}"
<f:convertDateTime pattern="HH" />
</h:inputText>
<h:outputText value=" h " />
<h:inputText id="myDateMinutes" maxlength="2" value="#{myBean.myDate}"
<f:convertDateTime pattern="mm" />
</h:inputText>
...
</h:form>
Run Code Online (Sandbox Code Playgroud)
但问题是,当我提交表单时,只保存最后一个元素.例如,如果我键入小时数,然后输入分钟数,则会覆盖小时数,结果为
| 00 | h | minutes |
Run Code Online (Sandbox Code Playgroud)
我试着设定
<h:inputText id="myDateHours" value="#{myBean.myDate.hours}></h:inputText>
<h:inputText id="myDateMinutes" value="#{myBean.myDate.minutes}></h:inputText>
Run Code Online (Sandbox Code Playgroud)
但我得到了
Cannot convert 01/01/70 01:00 of type class java.util.Date to int
Run Code Online (Sandbox Code Playgroud)
我不想用两个int字段替换我的日期字段(小时和分钟......)你有什么想法吗?
谢谢
我只是在一本Java夏季课的书中搞一些练习因为我有点领先,这意味着这不是功课.我收到一条错误消息,指出你无法转换String为int但是两者都是字符串,一个是变量,一个是数组.
就是这条线,我遇到了麻烦...... select = items[select];
public class CarpentryChoice {
public static void main(String[] args) {
String items [] = {"Table", "Desk", "Chair", "Couch", "Lazyboy"};
int price [] = {250, 175, 125, 345, 850};
String select;
Scanner scan = new Scanner(System.in);
System.out.println("Please enter an item to view it's price: ");
select = scan.nextLine();
for(int i=0; i < items.length; i++) {
select = items[select];
}
}
}
Run Code Online (Sandbox Code Playgroud)