这很烦人 - 我知道我会如何在网络上做到这一点......
我有一个 wpf 图像,我想将它的源属性绑定到一个方法,并从它的绑定项中传入一个属性。
IE。
<image source="GetMySource({binding name})" />
Run Code Online (Sandbox Code Playgroud)
GetMySource 在哪里
protected string GetMySource(string name)
{
return "images/"+name+".png";
}
Run Code Online (Sandbox Code Playgroud) 如何访问由JavaScript动态创建的控件(在CodeBehind中)的值?
我使用以下代码动态创建控件:
var counter = 0;
var words;
var foo;//span tag
function add(i) {
var counter = 0;
var words;
var foo;//span tag asp in page where the controls to be added
if (i == 'ad') {
counter++;
//Create an input type dynamically.
foo = document.getElementById("dynamic")
tbnam = document.createElement("input") //textbox
tbdes = document.createElement("input") //textbox
lbnam = document.createElement("Label")
lbdes = document.createElement("Label")
before = document.createElement('br')
after = document.createElement('br')
//Assign different attributes to the element.
wordsnam = document.createTextNode("Item")
wordsdes = document.createTextNode("Descrip")
tbnam.setAttribute("type", "TextBox"); …Run Code Online (Sandbox Code Playgroud) 首先,我查看了StackOverflow.com上的其他相关帖子,并且更改csproj文件中的路径并没有对此警告产生任何影响,如下所示.参考:为什么我在项目文件中找不到此警告.cs文件 还有: 如何连接xaml和xaml.cs文件
我有相当于MainWindow.xaml和MainWindow.xaml.cs.我决定将这两个文件移到Views文件夹中,因为我不喜欢我的主窗口视图与csproj文件以及App.xaml/App.xaml.cs文件一起浮动.
基本上:
查看/ MainWindow.xaml
查看/ MainWindow.xaml.cs
所以我的第一个问题:这是不允许的?我们是否需要将MainWindow.xaml和MainWindow.xaml.cs文件与csproj文件放在同一位置?
第二个问题:如果没有,那么我还缺少什么,因为我很确定我已经正确设置了所有路径?
<Page Include="Views\TimersHost.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="Views\TimersHost.xaml.cs">
<DependentUpon>Views\TimersHost.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
Run Code Online (Sandbox Code Playgroud)
我甚至将它们放在相同的标签中,因此编译器没有混淆的余地,但它仍然抱怨警告:文件'Views\TimersHost.xaml'的父文件'Views\TimersHost.xaml'在项目文件中找不到.cs'.
该警告实际上似乎表明它是MainWindow.xaml的父级是无法找到的,但从技术上讲没有父级,除非它指的是csproj文件本身,这就是为什么我问我们是否需要有MainWindow.xaml与csproj文件位于同一位置.
例如,在这篇文章中提到MainWindow.xaml应该放在Views文件夹中,这正是我想要做的: WPF中MVVM的项目结构
所以我很确定我只是遗漏了一些东西,但不知道它可能是什么,或者在哪里开始寻找.甚至我在App.xaml中的StartupUri也正确设置为指向该文件:
<Application
x:Class="TimersXP.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Views/TimersHost.xaml"
/>
Run Code Online (Sandbox Code Playgroud)
也许在TimersHost.xaml文件中我需要指定类的路径?x:Class ="Views/TimersXP.TimersHost"....这没有任何意义,并且无论如何都不起作用.
它是一个开源项目,所以这里是完整的csproj文件源:http://timersxp.codeplex.com/SourceControl/latest#VS2013/TimersXP/TimersXP.csproj (最新版本是最新的)
我有一个从我的代码隐藏类返回到aspx页面的公共属性:
window.MyWIndow.IsFull = '<%=this.IsFull%>';
Run Code Online (Sandbox Code Playgroud)
在代码隐藏中,它是这样定义的:
public bool IsFull
{
get;
set;
}
Run Code Online (Sandbox Code Playgroud)
现在,当我在我的 javascript 文件中使用它时,我有以下代码:
var isShow = myself.IsFull;
Run Code Online (Sandbox Code Playgroud)
这种方式isShow是'True'或'False'
我需要将其转换页面上的水平,所以isShow是boolean不是string。
所以我可以写if else逻辑
我该怎么做?
我的目标是将 XAML 中的元素属性绑定到类背后代码的属性,而 DataContext 仍然是 ViewModel。
原因是,我在 XAML 中有一些唯一的 UI 装饰属性,这些属性不是由 ViewModel 控制而是由后面的代码控制。
所以基本上我搜索类似的东西:
<Element
Attribute = "{Binding ThatOneCodeBehind.WhateverProperty}"
OtherAttribute1 = "{Binding StillDataContextSomething}"
OtherAttribute2 = "{Binding StillDataContextSomething}"
/>
Run Code Online (Sandbox Code Playgroud)
正确的绑定语法是什么Attribute="{Binding ThatOneCodeBehind:WhateverProperty}"?
DataTemplate如何创建后面代码中描述的控件实例?我在资源字典中找到了一个模板:
var template = resourceDictionary["Button"] as DataTemplate;
Run Code Online (Sandbox Code Playgroud)
现在我想使用 创建一个控件DataTemplate,但是如何呢?
var control = template.[MakeControl]?
Run Code Online (Sandbox Code Playgroud) 我能够为边界的移动制作动画:
private void MoveTo(Border target, double newX, double newY)
{
Vector offset = VisualTreeHelper.GetOffset(target);
var top = offset.Y;
var left = offset.X;
TranslateTransform trans = new TranslateTransform();
target.RenderTransform = trans;
DoubleAnimation anim1 = new DoubleAnimation(0, newY - top, TimeSpan.FromMilliseconds(500));
DoubleAnimation anim2 = new DoubleAnimation(0, newX - left, TimeSpan.FromMilliseconds(500));
trans.BeginAnimation(TranslateTransform.YProperty, anim1);
trans.BeginAnimation(TranslateTransform.XProperty, anim2);
}
Run Code Online (Sandbox Code Playgroud)
但我希望能够设置高度和宽度的增加以及位置的动画,以给出放大图像的印象(在我的情况和上面的例子中包含在边框中)).
这背后有代码吗?
好的,我尝试了缩放转换,但它似乎没有做任何事情 - 我需要一个故事板吗?
private void Zoom(Border target)
{
TranslateTransform trans = new TranslateTransform();
target.RenderTransform = trans;
DoubleAnimation anim1 = new DoubleAnimation(1, 2, TimeSpan.FromMilliseconds(1000));
DoubleAnimation anim2 …Run Code Online (Sandbox Code Playgroud) 当我这样做时,它运作得很好:
submitBtt.Text = "test";
Run Code Online (Sandbox Code Playgroud)
在页面加载功能中.
但是,当我试图像这样使用它时:
<asp:Button ID="submitBtt" OnClick="submitBtt_Click" runat="server" Text=' <%# test() %>' Width="80px" />
Run Code Online (Sandbox Code Playgroud)
测试函数在后面的代码中:
public string test()
{
return "test";
}
Run Code Online (Sandbox Code Playgroud)
我得到的只是一个没有文字的按钮.
试图谷歌它很多,找不到任何答案.
提前致谢.
在ASP.NET C#中,我想从UserControl的代码隐藏中显示ALERT('HI'),但不起作用:
用户控制:
<asp:UpdatePanel ID="updatepanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click();"/>
</ContentTemplate>
</asp:UpdatePanel>
Run Code Online (Sandbox Code Playgroud)
ASP.NET页面
protected void btnSubmit_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "s1", "javascript:alert('hi!')", true);
}
Run Code Online (Sandbox Code Playgroud)
更新:
忘了说ASP.NET页面本身是"prettyPhoto"的弹出窗口.
我试图将任何Mahapps.Metro.IconPacks中的图标分别分配给一个带有文本的按钮.
如果我想使用新的IconPack,我该怎么做?
实际上,我需要将Mahapps.Metro.IconPacks.PackIconModernKind转换为VisualBrush或canvas,或者实际上我可以使用任何东西将它放在一个按钮中.
任何帮助表示赞赏!
谢谢
code-behind ×10
c# ×6
wpf ×5
asp.net ×3
javascript ×3
xaml ×2
.net ×1
animation ×1
binding ×1
data-binding ×1
datatemplate ×1
html ×1
mvvm ×1
updatepanel ×1