我创建了一个Windows应用程序,用于在数据网格中显示Gmail对话.除Datagridview绑定之外的所有项都有效.我不知道绑定到Gridview中发生了什么..请查看我的代码片段并给我一个解决此问题的解决方案.在此先感谢..我的代码附加在下面...
GmailItem _gItem = null;
List<GmailItem> lstMail = new List<GmailItem>();
for (int i = 0; i < mailCount; i++)
{
_gItem = new GmailItem();
_gItem = client.GetMailItem(i);
lstMail.Add(_gItem);
}
_bindingMails.DataSource = lstMail;
dgMails.DataSource = _bindingMails;
Run Code Online (Sandbox Code Playgroud)
在设计器页面中,这是Datagridview的代码
this.dgMails.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgMails.Location = new System.Drawing.Point(6, 19);
this.dgMails.Name = "dgMails";
this.dgMails.Size = new System.Drawing.Size(504, 150);
this.dgMails.TabIndex = 0;
Run Code Online (Sandbox Code Playgroud)
此外,我在.CS页面中添加了此代码
dgMails.Dock = DockStyle.Fill;
dgMails.AutoGenerateColumns = true;
Run Code Online (Sandbox Code Playgroud) 我一直试图找到一种方法为多个事件添加相同的操作.
我将以下操作分配给#comid(这是一个选择菜单).
$("#comid").change(function()
{
comid = $("#comid").val();
//alert(comid);
$('#com_photo').addClass('loading');
$('#com_photo').load('ajax.php?requestType=ajax&action=get_com_photo&comid=' + comid, function() {
$('#com_photo').removeClass('loading');
$('#com_photo img').hide();
$('#com_photo img').fadeIn(1000);
alert('Image Loaded.');
});
});
Run Code Online (Sandbox Code Playgroud)
现在,上面的代码运行良好.当用户从选择菜单中选择一个项目时,触发更改事件并发出ajax请求,并显示图像以及一个提示"Image Loaded"的警告窗口.
但是,如果用户不使用鼠标而是使用键盘keyup/keydown从菜单中进行选择,我希望触发相同的操作.它默认情况下没有这样做,我希望它做但但似乎并非如此,所以我想为keyup或keydown事件分配相同的动作,但我不想写(或复制/粘贴)相同的代码再次.
经过一段时间的搜索我发现了关于bind(),我尝试这样做:
$("#comid").bind('keyup',function(event){
$("#comid").trigger('change');
}
Run Code Online (Sandbox Code Playgroud)
它工作,但当我使用密钥时,我看到警报窗口两次说"图像已加载",所以我发现该行为不需要,因为它似乎是两次请求.
有什么我做错了吗?还是有更好的替代方案,我想要完成的事情?
提前致谢 :)
我试图调用服务,并根据响应将用户重定向到另一个活动(登录).
如果我等到这样做,直到说,按钮单击,然后它工作正常(因为服务绑定),但如果我在onResume上,那么我得到以下异常:
ERROR/AndroidRuntime(2226): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to resume activity {...MyActivity}:
java.lang.NullPointerException
Run Code Online (Sandbox Code Playgroud)
我的代码是:
FooService fooService;
@Override
protected void onStart() {
super.onStart();
Intent intent = new Intent(this, FooService.class);
bindService(intent, fooServiceConnection, Context.BIND_AUTO_CREATE);
}
@Override
protected void onResume() {
//I would assume the service would have bound by now?
super.onResume();
doSomething();
}
Run Code Online (Sandbox Code Playgroud) 如何对列表框内容进行排序?在我看来,将它保留在UI层更有意义,因为排序不会影响我的业务逻辑,所以它可能在xaml或代码隐藏中.我无法弄明白该怎么做.
我有以下xaml,
<RichTextBox Name="RichTextBoxPostContent" Margin="0" Padding="8,8,8,0" IsReadOnly="True" Foreground="{x:Null}" Xaml="{Binding Path=PostContent}"/>
Run Code Online (Sandbox Code Playgroud)
和PostContent(一个字符串)有xaml存储为字符串,我不知道如何将它绑定到RichTextBox的Xaml属性,以下是PostContent的值,
<Section xml:space="preserve" HasTrailingParagraphBreakOnPaste="False" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"><Paragraph FontSize="11" FontFamily="Portable User Interface" Foreground="#FF000000" FontWeight="Normal" FontStyle="Normal" FontStretch="Normal" TextAlignment="Left"><Run Text="aaa" /></Paragraph></Section>
Run Code Online (Sandbox Code Playgroud) 我正在构建一个lua事件系统(在lua中),但是我希望能够从C中触发事件,我想将C函数绑定到lua函数,这样C函数可以在lua中触发事件,我打算用:
lua_register
Run Code Online (Sandbox Code Playgroud)
功能; 但是我似乎找不到像这样绑定我的lua函数的方法,看起来我需要一个lua函数来做同样的事情,但是从lua方面来说,我正在考虑做一些hack,将C函数绑定到lua,简单地调用'lua_register',但这对我来说似乎有些不安全.
那我该怎么做呢?
我有一个"简单"的问题,我创建了一个示例应用程序来说明.我希望b.getName()调用返回"barname",但它没有,我不知道如何让它工作.我已经在C#工作多年了,但此刻我觉得自己像个新手,因为这个后期绑定问题令我难过.
class Program
{
static void Main(string[] args)
{
bar b = new bar();
Console.WriteLine(b.getName());
Console.ReadLine();
}
}
class foo
{
string name = "fooname";
public string getName()
{
return this.name;
}
}
class bar:foo
{
string name = "barname";
}
Run Code Online (Sandbox Code Playgroud) 我创建了一个带有3个PART_s的控件,一个PART_根据绑定的类型而改变,但是在Control中更改的值不会更新Binding,它似乎可以作为OneWay绑定使用.
以下是我相信的代码的一部分:
<DataTemplate x:Key="BooleanDAView" DataType="{x:Type sys:Boolean}">
<CheckBox IsChecked="{Binding ., Mode=TwoWay}"/>
</DataTemplate>
<DataTemplate x:Key="DateTimeDAView" DataType="{x:Type sys:DateTime}">
<extToolkit:DateTimePicker Value="{Binding ., Mode=TwoWay}"/>
</DataTemplate>
<DataTemplate x:Key="Int32DAView" DataType="{x:Type sys:Int32}">
<extToolkit:IntegerUpDown Value="{Binding ., Mode=TwoWay}"/>
</DataTemplate>
<DataTemplate x:Key="StringDAView" DataType="{x:Type sys:String}">
<TextBox Text="{Binding ., Mode=TwoWay}"/>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
....
<ContentControl x:Name="PART_Content"
Grid.Row="0" Grid.Column="1"
Margin="{TemplateBinding Padding}"
VerticalAlignment="Center"
VerticalContentAlignment="Center"
Content="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
>
<ContentControl.ContentTemplateSelector>
<controls:TypeBasedDataTemplateSelector>
<controls:TypeBasedDataTemplateSelector.Templates>
<controls:TypedDictionary>
<sys:String x:Key="{x:Type sys:Boolean}">BooleanDAView</sys:String>
<sys:String x:Key="{x:Type sys:DateTime}">DateTimeDAView</sys:String>
<sys:String x:Key="{x:Type sys:Int32}">Int32DAView</sys:String>
<sys:String x:Key="{x:Type sys:String}">StringDAView</sys:String>
</controls:TypedDictionary>
</controls:TypeBasedDataTemplateSelector.Templates>
</controls:TypeBasedDataTemplateSelector>
</ContentControl.ContentTemplateSelector>
</ContentControl>
Run Code Online (Sandbox Code Playgroud)
对于内容我也试过...... RelativeSource={RelativeSource AncestorType=local:DABaseControl}但没有变化.
如果DataTemplate Binding使用 …
我已经将公共属性转换为公共变量,以使代码更简单,现在组合框的绑定机制将无法工作.我不能使用变量而不是属性?
工作代码:作为财产
internal class Utility
{
#region ReportOf
public enum ReportOf
{
Choose, All, Group, Person
}
private static Dictionary<ReportOf, string> _dictReportOf;
public static Dictionary<ReportOf, string> ReportOfCollection
{
get { return _dictReportOf; }
}
#endregion ReportOf
static Utility()
{
//initialize the collection with user friendly strings for each enum
_dictReportOf = new Dictionary<ReportOf, string>(){
{ReportOf.Choose, "Lütfen seçiniz..."},
{ReportOf.All, "Herkes"},
{ReportOf.Group, "Grup"},
{ReportOf.Person, "?ah?s"}};
}
}
Run Code Online (Sandbox Code Playgroud)
非工作端口:作为变量
internal class Utility
{
#region ReportOf
public enum ReportOf
{
Choose,
All,
Group,
Person …Run Code Online (Sandbox Code Playgroud) 框架:Silverlight 4
我有一个简单ChildWindow的用户名TextBox和密码PasswordBox.我已经为窗口的KeyDown事件附加了一个事件处理程序.
private void onKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
cancelButtonClick(null, null);
if (e.Key == Key.Enter)
okButtonClick(null, null);
}
Run Code Online (Sandbox Code Playgroud)
我想要实现的是当用户按下键盘上的Enter键时,程序的行为就像用户点击了OK按钮一样.
问题是验证.
Silverlight的PasswordBox的默认行为是在控件失去焦点时执行验证.我PasswordBox必然会遇到一些User对象.当我单击Enter按钮时,将调用事件处理程序,然后调用该事件处理程序okButtonClick(null, null).问题是当时PasswordBox还没有失去焦点,所以必然的user.Password财产PasswordBox仍然是空的.
我试图btnOK.Focus()在此之前放置,okButtonClick(null, null)但无济于事.
如何设置绑定,以便控件将更新每个文本更改而不是LostFocus事件的绑定?达到我需要的正确方法是什么?
binding ×10
c# ×4
wpf ×3
silverlight ×2
xaml ×2
android ×1
c ×1
datagridview ×1
focus ×1
gmail ×1
itemssource ×1
jquery ×1
keydown ×1
lua ×1
properties ×1
richtextbox ×1
service ×1
sorting ×1
validation ×1
windows ×1