我正在尝试使用WPF中的数据绑定在TextBox中显示格式化的十进制数.
目标1:在代码中设置小数属性时,在TextBox中显示2个小数位.
目标2:当用户与TextBox交互(输入)时,不要惹恼他/她.
目标3:绑定必须更新PropertyChanged上的源.
尝试1:没有格式化.
在这里,我们几乎从头开始.
<TextBox Text="{Binding Path=SomeDecimal, UpdateSourceTrigger=PropertyChanged}" />
Run Code Online (Sandbox Code Playgroud)
违反目标1. SomeDecimal = 4.5
将在TextBox中显示"4.50000".
尝试2:在绑定中使用StringFormat.
<TextBox Text="{Binding Path=SomeDecimal, UpdateSourceTrigger=PropertyChanged, StringFormat=F2}" />
Run Code Online (Sandbox Code Playgroud)
违反目标2.说SomeDecimal是2.5,TextBox显示"2.50".如果我们选择all并输入"13.5",我们在TextBox中以"13.5.00"结束,因为格式化程序"有用"地插入小数和零.
尝试3:使用Extended WPF Toolkit的MaskedTextBox.
http://wpftoolkit.codeplex.com/wikipage?title=MaskedTextBox
假设我正在正确阅读文档,掩码## 0.00表示"两个可选数字,后跟一个必需的数字,一个小数点,还有两个必需的数字.这迫使我说"可以进入的最大可能数字这个TextBox是999.99",但让我说我很好.
<xctk:MaskedTextBox Value="{Binding Path=SomeDecimal, UpdateSourceTrigger=PropertyChanged}" Mask="##0.00" />
Run Code Online (Sandbox Code Playgroud)
违反目标2. TextBox以___.__
选择它并输入5.75产量开始575.__
.获得5.75的唯一方法是选择TextBox并输入<space><space>5.75
.
尝试4:使用Extended WPF Toolkit的DecimalUpDown微调器.
http://wpftoolkit.codeplex.com/wikipage?title=DecimalUpDown
<xctk:DecimalUpDown Value="{Binding Path=SomeDecimal, UpdateSourceTrigger=PropertyChanged}" FormatString="F2" />
Run Code Online (Sandbox Code Playgroud)
违反目标3.DecimalUpDown愉快地忽略UpdateSourceTrigger = PropertyChanged.Extended WPF Toolkit Codeplex页面上的协调员之一建议在http://wpftoolkit.codeplex.com/discussions/352551/上修改ControlTemplate .这符合目标3,但违反了目标2,表现出与尝试2中相同的行为.
尝试5:使用样式数据触发器,仅在用户未编辑时才使用格式.
使用TextBox上的StringFormat绑定到double
即使这个目标满足所有三个目标,我也不想使用它.(A)文本框每行变为12行而不是1行,我的应用程序包含许多很多文本框.(B)我的所有文本框都有一个Style属性,该属性指向设置边距,高度和其他东西的全局StaticResource.(C)您可能已经注意到以下代码将绑定路径设置为两次,这违反了DRY主体.
<TextBox>
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Text" Value="{Binding Path=SomeDecimal, StringFormat=F2}" />
<Style.Triggers> …
Run Code Online (Sandbox Code Playgroud) 我的VS 2013输出窗口充满了这个:
iisexpress.exe Information: 0 : Request, Method=GET, Url=http://localhost:51741/api/Clients/?$filter=UniqueName eq '6269', Message='http://localhost:51741/api/Clients/?$filter=UniqueName eq '6269''
iisexpress.exe Information: 0 : Message='Clients', Operation=DefaultHttpControllerSelector.SelectController
iisexpress.exe Information: 0 : Message='MyProj.Controllers.ClientsController', Operation=DefaultHttpControllerActivator.Create
iisexpress.exe Information: 0 : Message='MyProj.Controllers.ClientsController', Operation=HttpControllerDescriptor.CreateController
iisexpress.exe Information: 0 : Message='Selected action 'GetClients()'', Operation=ApiControllerActionSelector.SelectAction
iisexpress.exe Information: 0 : Operation=HttpActionBinding.ExecuteBindingAsync
iisexpress.exe Information: 0 : Operation=QueryableAttribute.ActionExecuting
iisexpress.exe Information: 0 : Message='Action returned 'System.Collections.Generic.List`1[MyProj.Models.ClientDto]'', Operation=ReflectedHttpActionDescriptor.ExecuteAsync
iisexpress.exe Information: 0 : Message='Will use same 'JsonMediaTypeFormatter' formatter', Operation=JsonMediaTypeFormatter.GetPerRequestFormatterInstance
iisexpress.exe Information: 0 : Message='Selected formatter='JsonMediaTypeFormatter', content-type='application/json; charset=utf-8'', Operation=DefaultContentNegotiator.Negotiate
iisexpress.exe Information: 0 …
Run Code Online (Sandbox Code Playgroud) class Pair(models.Model):
first = models.ForeignKey(User, related_name='pair_first')
second = models.ForeignKey(User, related_name='pair_second')
class PairForm(forms.ModelForm):
class Meta:
model = Pair
fields = ('second',)
def clean(self):
first = None # how can I get first?
second = self.cleaned_data.get("second")
if (first == second):
raise ValidationError("You can't pair with yourself, silly.")
def pair_create(request):
if request.method == 'POST':
pair = Pair()
pair.first = request.user
form = PairForm(instance=pair, data=request.POST)
if form.is_valid():
form.save();
return HttpResponseRedirect(reverse('somewhere'))
else:
form = PairForm()
return render_to_response('something.html', {
'form': form,
}, context_instance=RequestContext(request))
Run Code Online (Sandbox Code Playgroud)
登录用户想要与另一个用户配对.它们显示为带下拉列表的表单.如果他们自己选择,则提出验证错误.
问题:在PairForm的clean(self) …
我似乎无法弄清楚为什么在构建setup.exe安装文件时发生此错误.
错误5 -3204:无法从文件C中提取索引为0的图标:\ dev\MyProj4\MyProjClientWpf\_ obj\x86\Release\MyProjClient.exe.ISEXP:错误:-3204:无法从文件C中提取索引为0的图标:\ dev\MyProj4\MyProjClientWpf\_ obj\x86\Release\MyProjClient.exe.
在快捷方式/文件夹部分,对于我正在生成的快捷方式,图标文件为空白,图标索引为0.无论默认图标是什么,我都没有指定一个,我甚至不想要一个.
有任何想法吗?
我有一个Garage
包含Cars
和Motorcycles
.汽车和摩托车是Vehicles
.他们来了:
public class Garage
{
public int Id { get; set; }
public virtual List<Car> Cars { get; set; }
public virtual List<Motorcycle> Motorcycles { get; set; }
public Garage()
{
Cars = new List<Car>();
Motorcycles = new List<Motorcycle>();
}
}
public abstract class Vehicle
{
public int Id { get; set; }
public string Make { get; set; }
public string Model { get; set; }
}
public class Car : …
Run Code Online (Sandbox Code Playgroud) 好的,这是我采取的步骤......
创建和自定义安装项目
设置安装项目版本= 1.0.0
构建安装项目
安装版本1.0.0
运行程序,在窗口的标题栏中 显示"v1.0.0"
更改程序中的代码以在窗口的标题栏中显示"v1.0.1"
设置安装项目RemovePreviousVersions = True
设置项目版本= 1.0.1
更改ProductCode(根据提示)
构建安装项目
安装版本1.0.1
运行程序,显示" v1.0.0"在窗口的标题栏中
新安装程序安装了旧版本的软件.在控制面板的"程序和功能"(以前称为"添加/删除程序")中,它显示已安装1.0.1版.我经历过多个教程,如http://www.simple-talk.com/dotnet/visual-studio/updates-to-setup-projects/
当您准备构建新版本的产品以替换旧版本时,请按照下列步骤操作:
- 增加version属性(参见图1).Visual Studio将显示一个消息框,提示您更改ProductCode和PackageCode.选择是.
- 将RemovePreviousVersions属性设置为true.
将RemovePreviousVersions属性设置为true会在安装新版本时从系统中删除以前版本的产品.由于产品由ProductCode Guid识别,因此更改ProductCode会创建新产品.也就是说,在安装新产品时会卸载旧产品.
如果我从控制面板手动删除1.0.0,然后安装1.0.1,程序运行正常显示"v1.0.1".
我在这里错过了什么?
我一直在看
DEBUG Exception while resolving variable 'exception_type' in template 'unknown'.
Run Code Online (Sandbox Code Playgroud)
在我的django日志中,然后是
VariableDoesNotExist: Failed lookup for key [exception_type] in
Run Code Online (Sandbox Code Playgroud)
接下来看起来像包含请求的字典列表的字符串表示,以及我的整个settings.py文件.
另一个例子:
DEBUG Exception while resolving variable 'lastframe' in template 'unknown'
Run Code Online (Sandbox Code Playgroud)
我觉得我没有足够的信息来调试这个.我所知道的是有一个exception_type
在未知模板中调用的变量.我的代码在任何地方都不包含字符串'exception_type'.
我该怎么调试呢?我应该在哪里看?
models.py:
class Player(models.Model):
name = models.CharField(max_length=50)
email = models.EmailField(max_length=50)
class Tournament(models.Model):
name = models.CharField(max_length=50)
class TournamentPlayer(models.Model):
tournament = models.ForeignKey(Tournament)
player = models.ForeignKey(Player)
paid = models.BooleanField()
def player_email(self):
return self.player.email
Run Code Online (Sandbox Code Playgroud)
admin.py:
class TournamentPlayerInline(admin.TabularInline):
model = TournamentPlayer
fields = ('player', 'paid', 'player_email')
@admin.register(Tournament)
class TournamentAdmin(admin.ModelAdmin):
inlines = [TournamentPlayerInline]
Run Code Online (Sandbox Code Playgroud)
我有一个内联问题.当我在管理站点中召开锦标赛时,我可以看到哪些玩家正在进行,以及他们是否付费.我还想显示播放器中包含的额外信息,例如电子邮件地址.
在TournamentPlayerInline中,我想我可以逃脱,fields = ('player', 'paid', 'player_email')
但我得到FieldError:为TournamentPlayer指定的未知字段(player_email).
我也尝试过fields = ('player', 'paid', 'player__email')
,但是我得到FieldError:为TournamentPlayer指定的未知字段(player__email).
如果我移动player_email
从fields
到readonly_fields
,我不再得到的错误,但球员电子邮件也不予显示.
这就是我所追求的:
如何从TournamentPlayerInline访问播放器属性?
Django 1.8.4
我认为我的问题是https://github.com/encode/django-rest-framework/issues/937,它应该由https://github.com/encode/django-rest-framework/pull/1003修复但是看来,无论是发送无字还是空字符串,DRF都不满意.
我正在使用Django 1.11.6和DRF 3.7.7
class Part(models.Model):
image = models.ImageField(null=True, blank=True)
class PartSerializer(serializers.ModelSerializer):
class Meta:
model = Part
fields = ('id', 'image')
class PartDetail(generics.RetrieveUpdateAPIView):
queryset = Part.objects.all()
serializer_class = PartSerializer
parser_classes = (MultiPartParser, FormParser)
# put image, works fine
with tempfile.NamedTemporaryFile(suffix='.jpg') as fp:
image = Image.new('RGB', (100, 200))
image.save(fp)
fp.seek(0)
data = {'image': fp}
self.client.put('/path/to/endpoint', data, format='multipart')
# clear image, attempt #1
data = {'image': None}
self.client.put('/path/to/endpoint', data, format='multipart')
AssertionError: {'image': ['The submitted data was not a …
Run Code Online (Sandbox Code Playgroud) 使用C#,WCF,WPF的客户端/服务器桌面应用程序.由于几乎所有操作都需要访问服务器(list/create/save/delete/etc),因此每个操作都有可能冻结整个UI.这是一个天真实现的例子,调用service.GetAll()
可能需要"很长"的时间(超过几百毫秒):
private void btnRefresh_Click(object sender, RoutedEventArgs e)
{
vm.Users.Clear();
foreach (var user in service.GetAllUsers())
vm.Users.Add(user);
}
Run Code Online (Sandbox Code Playgroud)
(题外话:我很想知道为什么名单有AddRange
和的ObservableCollection没有.)
BackgroundWorker
救援:
private void btnRefresh_Click(object sender, RoutedEventArgs e)
{
var worker = new BackgroundWorker();
worker.DoWork += (s, e) =>
{
Dispatcher.BeginInvoke((Action)delegate() { btnRefresh.IsEnabled = false; });
e.Result = service.GetAllUsers();
};
worker.RunWorkerCompleted += (s, e) =>
{
vm.Users.Clear();
foreach (var user in (List<UserDto>)e.Result)
vm.Users.Add(user);
Dispatcher.BeginInvoke((Action)delegate() { btnRefresh.IsEnabled = true; });
};
worker.RunWorkerAsync();
}
Run Code Online (Sandbox Code Playgroud)
(旁白:上面的代码已被简化,但这是它的要点.)
使用的代码BackgroundWorker …
django ×4
python ×3
wpf ×3
c# ×2
decimal ×1
django-forms ×1
iis-express ×1
image ×1
one-to-many ×1
rest ×1
textbox ×1
trace ×1
wcf ×1