一个简单的WPF问题.我想有一个内容="<"的按钮("后退按钮")如何实现这一点,因为以下是错误的:
Content="<"
Run Code Online (Sandbox Code Playgroud) 我正在准备考试和学习问题.但是我有一个问题,在我看来答案是错误的.这是正确答案是D的问题:
您使用Microsoft .NET Framework 4来创建Windows Presentation Foundation(WPF)应用程序.该应用程序有一个名为MainWindow的窗口,它有一个名为sp的StackPanel控件作为根元素.您想要创建一个Button控件,其中包含带有"Save"Text属性的TextBlock控件.您需要动态创建控件并将控件添加到sp.您应该在MainWindow类的构造函数中编写哪个代码段
A:
Button btn = new Button();
TextBlock text = new TextBlock();
text.Text = "Save";
btn.Content = text;
sp.DataContext = btn;
Run Code Online (Sandbox Code Playgroud)
B:
Button btn = new Button();
TextBlock text = new TextBlock();
text.Text = "Save";
btn.Content = text;
sp.Children.Add(btn);
Run Code Online (Sandbox Code Playgroud)
C:
Button btn = new Button();
TextBlock text = new TextBlock();
text.Text = "Save";
sp.Children.Add(btn);
sp.Children.Add(text);
Run Code Online (Sandbox Code Playgroud)
d:
Button btn = new Button();
TextBlock text = new TextBlock();
text.Text = "Save";
btn.ContentTemplateSelector.SelectTemplate(text, null);
sp.Children.Add(btn);
Run Code Online (Sandbox Code Playgroud)
在我看来,正确的答案是B?你有任何sugesstions?
问候,我想问一下,如果创建Singleton只有一个与db的活动连接是个好主意.我想做的是:1)我有一个wcf服务2)wcf服务从db获取数据3)我想创建一个这样的单例只有一个连接到db:
private static PersistanceSingleton _Instance;
public static PersistanceSingleton Instance
{
get
{
if (_Instance == null)
{
_Instance = new PersistanceSingleton();
}
return _Instance;
}
}
Run Code Online (Sandbox Code Playgroud)
我知道这不是一个理想的单身人士,但我只是为了这个后期目的写了它.我想在这里有一些持久性存储库,我将在构造函数中实例化它们.在我的服务类中,我将在构造函数中包含以下代码
_DBPersistanceSingleton = PersistanceSingleton.Instance;
Run Code Online (Sandbox Code Playgroud)
然后当一些请求到来时(例如GetUsersRequest)我想做类似的事情:
_DBPersistanceSingleton.GetUsers()
Run Code Online (Sandbox Code Playgroud)
在每次调用db之前,我还将检查SqlConnection是否打开.如果这是一个很好的做法,请告诉我.我之所以考虑这个解决方案,是因为大量用户将通过客户端应用程序连接到该服务
让我说我有一些像这样的ID输入:
ctl139_ctl00_txtValue
ctl140_ctl00_txtValue
ctl141_ctl00_txtValue
.....
xxxxxx_ctl00_txtValue
Run Code Online (Sandbox Code Playgroud)
如何使用CSS为这些输入应用相同的样式(其中ID遵循模式:xxxx_ctl00_txtValue)
我尝试了CSS3作为Minkiele的建议,但我已经完成了以下工作:
[id*="_ctl00_txtValue"]{ /* RULES */ }
Run Code Online (Sandbox Code Playgroud)
那么它应该为id包含我的字符串的所有元素应用样式.它适用于Chrome但不适用于IE8,但msdn告诉它应该可以工作.为什么它不起作用?
HEllo,有人可以解释一下WPF中的类级别事件处理程序吗?我在WPF中使用路由事件,但目前我读了一本书,我发现作者提到了类级事件处理程序.这种技术的实际用途是什么?
我正在使用ASP.NET MVC 4开发一个Web应用程序,我想以下列方式组织我的控制器和视图:
/Controller
/Admin
/LessonController.cs
/ExerciseController.cs
HomeController.cs
/Views
/Admin
/Lesson
/Index.cshtml
/Home
/Index.cshtml
Run Code Online (Sandbox Code Playgroud)
我尝试了以下代码来注册路由,但它不起作用:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Admin",
url: "Admin/{controller}/action/{id}",
defaults: new { controller = "Lesson", action = "Index", id = UrlParameter.Optional }
);
}
Run Code Online (Sandbox Code Playgroud)
你有什么建议吗?
我有一个页面如下:
<% using (Ajax.BeginForm("AddAnswer","Marketplace",new AjaxOptions() {HttpMethod = "POST" })){ %>
Run Code Online (Sandbox Code Playgroud)
AddAnsweraction将一些数据添加到db.我想要做的是:当成功添加答案时,将#answersdiv与当前答案传递给控制器.当答案尚未成功添加到db时 - 我想在#errorsdiv中显示适当的错误.我怎样才能做到这一点?
<Style x:Key="OrderGroupTemplateStyle" TargetType="{x:Type ContentControl}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Name.ShowDetailedInfo, UpdateSourceTrigger=PropertyChanged}" Value="False">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Border BorderBrush="Gray" BorderThickness="2" CornerRadius="3" Margin="2">
<StackPanel Background="LightGoldenrodYellow">
<ContentControl Content="{Binding Path=.}" Style="{StaticResource MyRecordViewModelShortStyle}"/>
<ListView ItemsSource="{Binding Path=Items}" Margin="4">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="HorizontalContentAlignment" Value="Stretch" /> <Setter Property="Padding" Value="2"/>
<EventSetter Event="MouseDoubleClick" Handler="ItemsControl_SelectionChanged"/>
</Style>
</ListView.ItemContainerStyle>
Run Code Online (Sandbox Code Playgroud)
当listview选择改变时,我想做一些工作.因为我正在使用样式我不能在ListView上使用SelectionChanged事件.我尝试使用EventSetter但编译项目时出现任何错误:
无法在样式中的Target标记上指定事件"MouseDoubleClick".请改用EventSetter.
有人可以帮帮我吗?
我有一些这样的风格:
<style type="text/css">
input[type=text]{
width:300px;
}
</style>
Run Code Online (Sandbox Code Playgroud)
上面的代码适用于chrome和firefox.为什么不在IE?我在Reports.aspx文件末尾的Reporting Services中使用此代码.
我正在用wpf写作.在我的viewModel中,我有一个打开新窗口的命令.但是,有时这个子窗口位于父窗口下.(例如,如果我在我的应用程序中工作,那么打开浏览器并希望返回我的应用程序).窗口打开如下:
MyViewModel vm = new MyViewModel(oper);
Mywindow window = new MyWindow();
//Initialize viewModel and set window.DataContext to this viewModel
CWPFWindowWithViewModelHelper<IWindowWithViewModel>.InitializeViewModel(window, vm);
window.ShowDialog();
Run Code Online (Sandbox Code Playgroud)
我希望这个子窗口在打开时始终可见.我怎样才能做到这一点?
问候,在我的asp.net mvc应用程序中,我有一个列表框呈现如下:
<%= Html.ListBox("localization", (Model as SeekWeb.Models.CreateMessageViewModel).Localizations.AsEnumerable())%>
Run Code Online (Sandbox Code Playgroud)
有没有办法让每个列表框项目的复选框?如果选中复选框,则选择相应的列表框项.
我有两节课:
public class Exercise
{
public Guid Id {get;set;}
public string Name {get;set;}
public List<ExerciseItem> Items {get;set;}
}
public class ExerciseItem
{
public Guid Id {get;set;}
public string Name {get;set;}
public string Content {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
我也有创建一个Exercise对象的观点.该视图上有一个名为"添加练习项"的按钮,其中我动态调用ajax方法返回ExerciseItem对象的局部视图.视图正确返回.这个观点如下:
@model Elang.Models.ExerciseItem
<div>
<input type="hidden" name="Items.Index" value="@Model.Id" />
<input type="hidden" id="Items@(Model.Id)__Id" name="Items[@Model.Id].Id" value="@Model.Id" />
<input type="text" id="Items@(Model.Id)__Content" name="Items[@Model.Id].Content" class="inputText"/>
</div>
Run Code Online (Sandbox Code Playgroud)
问题是当我提交表单并调用我的"Create"方法时:
[HttpPost]
public ActionResult Create(Exercise exercise)
{
//add exercise to db
//HOWEVER!!
//exercise.Items is empty
}
Run Code Online (Sandbox Code Playgroud)
我的项目为空.我究竟做错了什么?有人可以给我一些建议我应该怎么做才能解决这个问题?