binding

Binding to static class property

吃可爱长大的小学妹 提交于 2019-12-17 05:01:17
问题 I want to bind a textblock text to a property of a static class. Whenever the property value of the static class changes, it should reflect to the textblock which is on the other window or custom control. 回答1: You can bind to ANY property on a static class using the x:Static markup extension but if thy do not implement any change tracking, it might cause errors on the refresh! <TextBlock Text="{Binding Source={x:Static sys:Environment.MachineName}}" /> 回答2: This has worked for me: Text="

How do I invert BooleanToVisibilityConverter?

主宰稳场 提交于 2019-12-17 02:58:23
问题 I'm using a BooleanToVisibilityConverter in WPF to bind the Visibility property of a control to a Boolean . This works fine, but I'd like one of the controls to hide if the boolean is true , and show if it's false . 回答1: Implement your own implementation of IValueConverter. A sample implementation is at http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx In your Convert method, have it return the values you'd like instead of the defaults. 回答2: Instead of inverting

How can you clone a WPF object?

本秂侑毒 提交于 2019-12-17 02:33:10
问题 Anybody have a good example how to deep clone a WPF object, preserving databindings? The marked answer is the first part. The second part is that you have to create an ExpressionConverter and inject it into the serialization process. Details for this are here: http://www.codeproject.com/KB/WPF/xamlwriterandbinding.aspx?fid=1428301&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2801571 回答1: The simplest way that I've done it is to use a XamlWriter to save the WPF object as a string. The

How to preserve control state within tab items in a TabControl

随声附和 提交于 2019-12-17 02:23:39
问题 I am a newcomer to WPF, attempting to build a project that follows the recommendations of Josh Smith's excellent article describing The Model-View-ViewModel Design Pattern. Using Josh's sample code as a base, I have created a simple application that contains a number of "workspaces", each represented by a tab in a TabControl. In my application, a workspace is a document editor that allows a hierarchical document to be manipulated via a TreeView control. Although I have succeeded in opening

How to bind multiple values to a single WPF TextBlock?

冷暖自知 提交于 2019-12-17 02:04:39
问题 I'm currently using the TextBlock below to bind the value of a property named Name : <TextBlock Text="{Binding Name}" /> Now, I want to bind another property named ID to the same TextBlock . Is it possible to bind two or more values to the same TextBlock ? Can it be done with simple concatenation, like Name + ID and, if not, how else could this be approached? 回答1: You can use a MultiBinding combined with the StringFormat property. Usage would resemble the following: <TextBlock> <TextBlock

Bind to a value defined in the Settings

主宰稳场 提交于 2019-12-17 01:58:06
问题 In WPF, Can I use binding with values defined in Settings? If this is possible, please provide a sample. 回答1: First, you need to add a custom XML namespace that will design the namespace where the settings are defined: xmlns:properties="clr-namespace:TestSettings.Properties" Then, in your XAML file, access the default settings instance using the following syntax: {x:Static properties:Settings.Default} So here is the final result code: <ListBox x:Name="lb" ItemsSource="{Binding Source={x

List comprehension rebinds names even after scope of comprehension. Is this right?

心不动则不痛 提交于 2019-12-16 19:45:13
问题 Comprehensions are having some unexpected interactions with scoping. Is this the expected behavior? I've got a method: def leave_room(self, uid): u = self.user_by_id(uid) r = self.rooms[u.rid] other_uids = [ouid for ouid in r.users_by_id.keys() if ouid != u.uid] other_us = [self.user_by_id(uid) for uid in other_uids] r.remove_user(uid) # OOPS! uid has been re-bound by the list comprehension above # Interestingly, it's rebound to the last uid in the list, so the error only shows # up when len

List comprehension rebinds names even after scope of comprehension. Is this right?

北战南征 提交于 2019-12-16 19:45:07
问题 Comprehensions are having some unexpected interactions with scoping. Is this the expected behavior? I've got a method: def leave_room(self, uid): u = self.user_by_id(uid) r = self.rooms[u.rid] other_uids = [ouid for ouid in r.users_by_id.keys() if ouid != u.uid] other_us = [self.user_by_id(uid) for uid in other_uids] r.remove_user(uid) # OOPS! uid has been re-bound by the list comprehension above # Interestingly, it's rebound to the last uid in the list, so the error only shows # up when len

List comprehension rebinds names even after scope of comprehension. Is this right?

此生再无相见时 提交于 2019-12-16 19:44:14
问题 Comprehensions are having some unexpected interactions with scoping. Is this the expected behavior? I've got a method: def leave_room(self, uid): u = self.user_by_id(uid) r = self.rooms[u.rid] other_uids = [ouid for ouid in r.users_by_id.keys() if ouid != u.uid] other_us = [self.user_by_id(uid) for uid in other_uids] r.remove_user(uid) # OOPS! uid has been re-bound by the list comprehension above # Interestingly, it's rebound to the last uid in the list, so the error only shows # up when len

Color DataGridCell by Cellvalue

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-14 03:59:52
问题 i've a WPF DataGrid with different count of columns. I want to color the single cells dependent by the value. For example: If the cell-value is 0, then red. These are my experiments: <DataGrid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" x:Name="DataGrid" SelectionUnit="Cell"> <DataGrid.CellStyle> <Style TargetType="{x:Type DataGridCell}"> <Style.Triggers> <!--experiment 1 --> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Value, NotifyOnSourceUpdated=True,