我得到InputStream了一个getResourceAsStream(),我设法通过传递返回InputStream到文件读取BufferedReader.
有什么方法可以写入文件吗?
在JavaScript中,我可以使用apply将数组作为参数传递给函数:
var f = function (n,m) {},
args = [1,2];
f.apply(null, args);
Run Code Online (Sandbox Code Playgroud)
我现在需要在PHP中做类似的事情,即将一个项目数组作为"单独"参数传递给函数.
有什么办法可以做到吗?
我有以下内容GridView:
<ListView Name="TrackListView" ItemContainerStyle="{StaticResource itemstyle}">
<ListView.View>
<GridView>
<GridViewColumn Header="Title" Width="100" HeaderTemplate="{StaticResource BlueHeader}" DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn Header="Artist" Width="100" HeaderTemplate="{StaticResource BlueHeader}" DisplayMemberBinding="{Binding Album.Artist.Name}" />
<GridViewColumn Header="Album" Width="100" HeaderTemplate="{StaticResource BlueHeader}" DisplayMemberBinding="{Binding Album.Name}"/>
<GridViewColumn Header="Length" Width="100" HeaderTemplate="{StaticResource BlueHeader}"/>
</GridView>
</ListView.View>
</ListView>
Run Code Online (Sandbox Code Playgroud)
现在,我想在右边的有界项目上显示一个上下文菜单,这将允许我在后面的代码中处理事件时检索所选项目.
我可以通过哪种方式实现这一目标?
[更新]
按照Dennis Roche的代码,我现在有了这个:
<ListView Name="TrackListView" ItemContainerStyle="{StaticResource itemstyle}">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="OnListViewItem_PreviewMouseLeftButtonDown" />
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Header="Add to Playlist"></MenuItem>
</ContextMenu>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Title" Width="100" HeaderTemplate="{StaticResource BlueHeader}" DisplayMemberBinding="{Binding Name}"/> …Run Code Online (Sandbox Code Playgroud) 我没有在我的应用程序中附加PreviewKeyUp事件TextBox并检查按下的键是否为Enter键然后执行操作,而是决定实现TextBox包含DefaultAction事件的扩展版本,该事件在按下Enter键时触发TextBox.
我所做的基本上是创建一个新的类,从TextBox公共事件延伸DefaultAction,如下:
public class DefaultTextBoxControl:TextBox
{
public event EventHandler<EventArgs> DefaultAction = delegate { };
public DefaultTextBoxControl()
{
PreviewKeyUp += DefaultTextBoxControl_PreviewKeyUp;
}
void DefaultTextBoxControl_PreviewKeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key != Key.Enter)
{
return;
}
DefaultAction(this, EventArgs.Empty);
}
}
Run Code Online (Sandbox Code Playgroud)
然后我使用我的应用程序中的这个自定义文本框,如(xaml):
<Controls:DefaultTextBoxControl DefaultAction="DefaultTextBoxControl_DefaultAction">
</Controls:DefaultTextBoxControl>
Run Code Online (Sandbox Code Playgroud)
现在,在我学习WPF的过程中,我已经意识到几乎大多数时候都有一种"更酷"(希望更容易)的方式来实现
...所以我的问题是,我怎样才能改善上述控制? 或者是否有另一种方法可以进行上述控制?...也许只使用声明性代码而不是声明性(xaml)和程序性(C#)?
我需要能够在将对象添加到a时触发事件Queue<Delegate>.
我创建了一个扩展的新类Queue:
public delegate void ChangedEventHandler(object sender, EventArgs e);
public class QueueWithChange<Delegate> : Queue<Delegate>
{
public event ChangedEventHandler Changed;
protected virtual void OnChanged(EventArgs e) {
if (Changed != null)
{
Changed(this, e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后从另一个类附加事件,如:
QueueWithChange<TimerDelegate> eventQueue = new QueueWithChange<TimerDelegate>();
//
eventQueue.Changed += new ChangedEventHandler(delegate(object s, EventArgs ex) {
//This event is not being triggered, so this code is unreachable atm...and that is my problem
if (eventQueue.Count > 0)
{
eventQueue.Dequeue().Invoke(new DispatcherTimer() { Interval = …Run Code Online (Sandbox Code Playgroud) 假设你在艺术家和粉丝之间有很多桌子.在设计表时,你是否设计了这样的表:
ArtistFans
ArtistFanID (PK)
ArtistID (FK)
UserID (FK)
(ArtistID and UserID will then be contrained with a Unique Constraint
to prevent duplicate data)
Run Code Online (Sandbox Code Playgroud)
或者你为两个相关领域构建使用复合PK:
ArtistFans
ArtistID (PK)
UserID (PK)
(The need for the separate unique constraint is removed because of the
compound PK)
Run Code Online (Sandbox Code Playgroud)
使用前一个模式是否有任何优势(可能是索引?)?
我尝试过使用MSDN中的示例,但它们似乎只适用于Windows窗体.例如,使用.InvokeRequired的方法依赖于窗体控件,但是此方法不适用于WPF控件.Backgound工人方法也抛出InvalidOperationException-
调用线程无法访问此对象,因为另一个线程拥有它.
那么如何在WPF环境中完成呢?
我记得在某处读过(我认为这是在Crockford的一篇论文中),使用数组文字[]比使用new Array();符号更好.
但我真的不记得一个优于另一个的优点.
任何人都可以向我解释为什么前者比后者更受欢迎?
这是我能想到为什么[]比new Array();以下更好的原因之一:
var Array = function () { };
Run Code Online (Sandbox Code Playgroud)
覆盖Array对象会破坏代码......!
还有其他原因吗?
我一直在使用NavigationService的Navigate方法导航到我的WP7的Silverlight应用程序的其他页面:
NavigationService.Navigate(new Uri("/Somepage.xaml?val=dreas", UriKind.Relative));
Run Code Online (Sandbox Code Playgroud)
从Somepage.xaml,我然后检索查询字符串参数,如下所示:
string val;
NavigationContext.QueryString.TryGetValue("val", out val);
Run Code Online (Sandbox Code Playgroud)
我现在需要一种使用类似方式传递复杂对象的方法.每次我需要将对象传递给新页面时,如何在不必序列化对象的情况下执行此操作?
c# ×5
wpf ×3
javascript ×2
xaml ×2
apply ×1
arrays ×1
contextmenu ×1
delegates ×1
dom ×1
events ×1
file-io ×1
java ×1
jquery ×1
literals ×1
navigation ×1
php ×1
queue ×1
silverlight ×1
sql ×1
web-services ×1