Windows Phone 7.5应用程序.
我想重构我的应用程序,就像在Visual Studio中创建单独的嵌套文件夹以便更好地管理.例如

这种文件结构会影响应用程序的性能吗?
我有一个简单的自定义控件:
namespace Application.Custom_Controls
{
public class ReadOnlyTextBox : TextBox
{
public ReadOnlyTextBox()
{
this.DefaultStyleKey = typeof(ReadOnlyTextBox);
this.IsReadOnly = true;
}
}
}
Run Code Online (Sandbox Code Playgroud)
并使自定义样式使控件看起来像TextBlock(在App.xaml中).
<Application
x:Class="Application.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:tb = "clr-namespace:Application.Custom_Controls"
>
<!--Application Resources-->
<Application.Resources>
<Style x:Key="ReadOnlyTextBox" TargetType="tb:ReadOnlyTextBox">
//...
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="tb:ReadOnlyTextBox">
//...
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
但是当我在我的应用程序中使用它时它根本不显示.如果我删除它,它作为普通TextBox显示this.DefaultStyleKey = typeof(ReadOnlyTextBox);.
如何将此样式应用于代码后面的自定义控件?
顺便说一句,这种风格在xaml中运行良好Style="{StaticResource ReadOnlyTextBox}",但在这种情况下我不能使用xaml.
提前致谢.
框架: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事件的绑定?达到我需要的正确方法是什么?
当尝试使用Clipboard.GetTextWindows Phone应用程序中的方法从剪贴板获取文本时,它总是抛出SecurityException(预期的行为).
这有什么黑客或解决方法吗?
我知道我在WP7(不是WP7.1)中做到了这一点,我无法弄清楚我做了什么.
所以基本上我在记事本中打开了我的WP7 csproj文件,添加了以下几行:
<UsingTask TaskName="ShaderBuildTask.PixelShaderCompile" AssemblyName="ShaderBuildTask, Version=1.0.3072.18169, Culture=neutral, PublicKeyToken=44e467d1687af125" />
<Target Name="EffectCompile" Condition="'@(Effect)' != '' ">
<PixelShaderCompile Sources="@(Effect)">
<Output TaskParameter="Outputs" ItemName="Resource" />
</PixelShaderCompile>
</Target>
<PropertyGroup>
<PrepareResourcesDependsOn>EffectCompile;$(PrepareResourcesDependsOn)</PrepareResourcesDependsOn>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
并且System.Windows.Media.Effects不包含
ShaderEffect
PixelShader
Run Code Online (Sandbox Code Playgroud)
如果有人知道我做错了什么或者有一个WP7模板,这将是非常棒的.谢谢.我不是要使用XNA着色器.
我对WPF和.Net编程一般都是新手.我已下载此源代码.
现在,它有一个包含Paris.Controls csproj的解决方案.
这最初是为Silverlight而制作的,当我尝试将referance添加到这些控件的输出dll时,我收到一个错误:
Error 1 Unknown build error,
'Cannot resolve dependency to assembly
'System.Windows, Version=2.0.5.0, Culture=neutral,
PublicKeyToken=7cec85d7bea7798e'
because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies
must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.
Line 9 Position 80.' C:\Users\Eric\Documents\Visual Studio
2010\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml 9 80
WpfApplication1
Run Code Online (Sandbox Code Playgroud)
经过一段谷歌搜索,我发现它最喜欢,因为Silverlight - WPF转换.Silverlight使用与WPF不同的依据.我认为这有点愚蠢,因为据我所知,Silverlight是WPF的减法,但没关系.
所以我的问题是我应该怎么做以及如何做?我应该编辑Paris.Controls并使其WPF可用吗?改变参考和类似的东西?如果这就是我应该做的,我该怎么做?如果没有,我的选择是什么?
埃里克,请帮助你们,真诚的你们
这是我现在的功能,显然不起作用.它不起作用的原因是因为WebClient是异步的并且data在WebClient填充并且在XML阅读器上崩溃之前是空的.如何在此函数中调用WebClient并仍然允许它在ServerResult需要或不需要外部事件处理程序时根据需要返回?
static public ServerResult isBarcodeCorrectOnServer(string barcode)
{
Dictionary<string, IPropertyListItem> dict = configDictionary();
string urlString = (string.Format("http://www.myurl.com/app/getbarcodetype.php?realbarcode={0}&type={1}", barcode, dict["type"]));
WebClient wc = new WebClient();
string data = "";
wc.DownloadStringCompleted += (sender, e) =>
{
if (e.Error == null)
{
//Process the result...
data = e.Result;
}
};
wc.DownloadStringAsync(new Uri(urlString));
StringReader stream = new StringReader(data);
var reader = XmlReader.Create(stream);
var document = XDocument.Load(reader);
var username = document.Descendants("item");
var theDict = username.Elements().ToDictionary(ev => ev.Name.LocalName, ev => ev.Value);
if (theDict.ContainsKey("type") …Run Code Online (Sandbox Code Playgroud) 例如:有一个列表框:
<ListBox Margin="24,107,12,28" Name="lb">
<TextBlock Text="Text" TextWrapping="Wrap" FontSize="22" Visibility="Collapsed" />
<TextBlock Text="Text2" TextWrapping="Wrap" FontSize="22" Visibility="Collapsed" />
<TextBlock Text="Text3" TextWrapping="Wrap" FontSize="22" Visibility="Collapsed" />
</ListBox>
Run Code Online (Sandbox Code Playgroud)
如何以编程方式更改TextBlocks的可见性属性?
我有一个名为ItemGrid的usercontrol,带有一个带图像的按钮,我将图像移动到一个controltemplate,所以我可以正确调整它的大小:
<Button x:Name="btnOrder" Click="btnOrder_Click" HorizontalAlignment="Right" Width="48" Height="48" Margin="0,0,0,100">
<Button.Template>
<ControlTemplate>
<Image x:Name="imgOrder" Source="/Images/dark/appbar.food.png" Stretch="None"/>
</ControlTemplate>
</Button.Template>
</Button>
Run Code Online (Sandbox Code Playgroud)
在MainPage中我想根据当前选择它们设置正确的图像(暗/亮)
private void detecttheme()
{
Visibility v = (Visibility)Resources["PhoneLightThemeVisibility"];
if (v == System.Windows.Visibility.Visible)
{
uri = new Uri("/Images/light/appbar.food.png", UriKind.Relative);
imgSource = new BitmapImage(uri);
ItemGrid.imgOrder.Source = imgSource;
}
else ....
Run Code Online (Sandbox Code Playgroud)
这给了我:在我将imgOrder移动到controltemplate之后,UserControls.ItemGrid'不包含'imgOrder'的定义
我已经尝试使用findname,但这也为img提供了一个nullreference异常
//Use FindName because we cannot directly reference the image because it's in a control template
Image img = ItemGrid.FindName("imgOrder") as Image;
img.Source = imgSource;
Run Code Online (Sandbox Code Playgroud)
我也尝试将findname放在控件的OnApplyTemplate中,但似乎根本没有被解雇?
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
Image …Run Code Online (Sandbox Code Playgroud) 如何在canvas元素周围添加边框?边框应与画布大小相同.
我正在使用下面的代码,但无法实现结果.
<Canvas Background="Transparent" Margin="69,-30,56,315" x:Name="LetterCanvas" >
<Border x:Name="CanvasBorder" BorderThickness="5" Height="271" Width="325">
</Border></Canvas>
Run Code Online (Sandbox Code Playgroud)