|
I am trying to hide a text block. When a Checkbox is checked, it should be hidden. When it's unchecked the textblock should be visible.
The checkbox is bound to an object called SelectedProcess. If SelectedProcess is null, the textblock should be hidden.
Here's my XAML:
<CheckBox IsChecked="{Binding SelectedProcess.Enabled}"
IsEnabled="{Binding AllowProcessEdit}"
x:Name="EnabledCheckbox"
Foreground="Black"
FontSize="12"
Margin="10,0,0,0"
VerticalAlignment="Center"
HorizontalAlignment="Stretch"/>
<TextBlock Grid.Row="4"
Foreground="Red"
FontWeight="Bold"
FontSize="12"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Text="This process is disabled"
Margin="10,0,0,0">
<TextBlock.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedProcess}" Value="Null">
<Setter Property="UIElement.Visibility" Value="Hidden"/>
</DataTrigger>
<DataTrigger Binding="{Binding SelectedProcess.Enabled}" Value="True">
<Setter Property="UIElement.Visibility" Value="Hidden"/>
</DataTrigger>
<DataTrigger Binding="{Binding SelectedProcess.Enabled}" Value="False">
<Setter Property="UIElement.Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
It works when SelectedProcess is NOT null, but when SelectedProcess IS null, the text is still visible.
What am I doing wrong here?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
|
That did it. Thank you!
If it's not broken, fix it until it is
|
|
|
|
|
Your issue seems fixed, which is great.
However, I wonder why you use datatriggers to accomplish this.
Consider doing it through binding instead with the help of a converter.
If the visibility of the texblock is always directly related to the checkbox being checked / unchecked, then you could use elementbinding to do so.
<TextBlock Visibility="{Binding IsChecked, Converter={StaticResource boolToVisibilityConverter}, ElementName=CheckBoxName}" />
The resulting XAML is simpler and achieves the same result.
|
|
|
|
|
Hi. i have one question.
I would like to specify the area to zoom in (ex . fence -> rect type )
well. i saw seadragon open source but i can't understand fitBounds Method
too hard viewportOrigin & viewportWidth
how can i calculation multiscaleImage viewport with two points
and make fit bound feature
please help me.
note ) i don't use map control. only multiscaleImage
|
|
|
|
|
I'm trying set focus to a UI element from within a view model.
First, following this example[^] I created the Attached Property.
Then in my VM I created a bool property called "IsHourlyMinutesFocused":
private bool _IsHourlyMinutesFocused;
public bool IsHourlyMinutesFocused
{
get { return _IsHourlyMinutesFocused; }
set
{
if (_IsHourlyMinutesFocused != value)
{
_IsHourlyMinutesFocused = value;
RaisePropertyChanged("IsHourlyMinutesFocused");
}
}
}
Next, I added it to the XAML:
<TextBox Grid.Row="0"
Grid.Column="2"
VerticalAlignment="Center"
classes:FocusExtension.IsFocused="{Binding IsHourlyMinutesFocused}"
Focusable="True"
Text="{Binding SelectedProcess.ProcessSchedule.HourlyMinutes}"
Margin="2,0,2,0"
Width="40"/>
When I set IsHourlyMinutesFocused = true, nothing happens. The OnIsFocusedPropertyChanged event in the DP never fires.
What's wrong here?
If it's not broken, fix it until it is
|
|
|
|
|
Hi ,
I am new in coding WPF MVVM apps.
My question is how to change le language using a combobox at Runtime.
I tried the static resources and it worked well , but trying to change it Runtime using Threading.thread class didn't work.
Is there any possibility to solve that problem.
Thanks a lot for your help.
|
|
|
|
|
This is now the FOURTH time you have asked the same question.
DO NOT repost the same question. It won't get your question answered any quicker; if anything, it will just annoy the people who would otherwise be trying to help you, and result in all of your questions being ignored.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Hi ,
I need to change culture mainly between two languages ; italian and English using the Combobox in WPF MVVM.
I tried to databind the ViewModel with my Mainview but I didn't succeed.
I will be so thankful if someone could help.
Here is my Combobox declaration in xaml :
<ComboBox IsEditable="True" Text="Language" HorizontalAlignment="Right" VerticalAlignment="Top" Width="95" Margin="34,21,34,0" ItemsSource="{Binding Languages}" SelectedItem="{Binding SelectedLanguage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="#FF434C64" removed="Green" Height="24.96" />
Here is View Model definition :
public void ChangeLanguage()
{
if (SelectedLanguage == "en")
{
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
}
else
if (SelectedLanguage == "it-IT")
{
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("it-IT");
}
}
Here the declaration within the construcor of my View Model
public ViewModel()
{
LoadData();
ChangeLanguage();
Login = new DelegateCommand(this.Logging, delegate()
{
return (!String.IsNullOrEmpty(Username) && !String.IsNullOrEmpty(Password) && !String.IsNullOrEmpty(Email));
});
Register = new DelegateCommand(this.Registering, delegate()
{
return (!String.IsNullOrEmpty(Username) && !String.IsNullOrEmpty(Password) && !String.IsNullOrEmpty(Email));
});
|
|
|
|
|
Where is your SelectedLanguage property declaration? What does it look like?
|
|
|
|
|
I am implementing scrollable text in a custom control. Each line of text has its own Visual. In the simple case of horizontal scrolling, I replace the Transform of each Visual to produce the desired effect. The scroll bar moves, but the text does not. Am I missing a step that causes the new Transform objects to be reflected (presumably as parameter changes) in the Composition Tree?
Ron Martin
|
|
|
|
|
The Microsoft Icon design guidelines http://msdn.microsoft.com/en-us/library/aa511280.aspx[^] specifies the recommended set of icon sizes for a Windows desktop application.
Maybe I haven't looked through enough search results, but I cannot find a reference on how to add the set of sizes of the icon to a WPF desktop application. All I have found is how to add the one icon for the application main window frame.
Can someone offer references or instructions?
All my previous WPF work has been kiosk-style (dedicated instrument control) applications that didn't need icons!
Thanks.
|
|
|
|
|
What I didn't recall was that all of the icon sizes co-exist in the single .ico file.
|
|
|
|
|
I have Multiple Lists that are bound to multiple TreeViewItems within the Tree as in the code below. This is working perfectly to display the bound items; however, I couldn't figure out how to get the selected item value. For example, if the user clicks the color Blue, I would like to be able to get that value, in this case "Blue," in order to be able to bind to a property in the ViewModel
<TreeView>
<TreeViewItem Header="Category" ItemsSource="{Binding Categories}" />
<TreeViewItem Header="Colors" ItemsSource="{Binding Colors}" />
</TreeView>
|
|
|
|
|
Are you only going one way? UI -> VM? If so, there is a SelectedItem bindable property on the TreeView that you can use.
If you want two-way binding (set the selection from the VM), that is a lot more work.
|
|
|
|
|
It is binding from UI to VM. I just need to get the value of the selecteditem, and the SelectedItem of the TreeView is Read Only. So how do I get the Value of the Selected Item? Thanks in advance.
|
|
|
|
|
So what is the issue? SelectedItem contains your selected item. It is only read only to you. The TreeView control sets internally. You do need to use one way binding though.
|
|
|
|
|
This guy [^]has some excellent treeview article which may help you.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Why can't you just bind SelectedItem from the TreeView to your VM ?
<TreeView SelectedItem="{Binding SelectedItem, mode=TwoWay}">
<TreeViewItem Header="Category" ItemsSource="{Binding Categories}" />
<TreeViewItem Header="Colors" ItemsSource="{Binding Colors}" />
</TreeView>
|
|
|
|
|
The +/- is a styled ToggleButton (ControlTemplate\Grid\ToggleButton).
The content is a normal styled ContentPresenter(s) hosted in an ItemsPresenter (ControlTemplate\Grid\ItemsPresenter). An ItemsPresenter is a collection of Items. For the TreeView, these are additional ItemsPresenter(s) to do the hierarchy.
If I was going to do what you want to do, I'd remove the ToggleButton from the TreeViewItem style (to hide it) and place it in the item template (item template is != item style). You'll notice the trigger for HasItems sets the visibility to HIDDEN if it doesn't have items vs. COLLAPSED so the tree doesn't get misaligned.
From the ItemTemplate you'd use the same bindings pretty much. Except the DataTemplate would be something like
<DataTemplate>
<Grid>
<Button ... HorizontalAlignment="Left" VerticalAlignment="Top" />
<ToggleButton ... HorizontalAlignment="Left" VerticalAlignment="Top" />
</Grid>
</DataTemplate>
Just an FYI, this will give you what you want visually, but not from a usability stand point (maybe). You won't be able to click on the button in the upper left corner where the +/- is.
|
|
|
|
|
You don't lose any functionality by putting stuff in the DataTemplate. What I said earlier about the "bindings are mostly the same" was slightly misleading... they are, but you need to repoint the functionality ones (like the ToggleButton) to the TreeViewItem (relative source / find ancestor TreeViewItem) and not your data item. Remember, there is *always* a TreeViewItem. If you give the ItemsSource a TreeViewItem, WPF will use that instance of it, otherwise, it'll wrap your object in an implied one it creates.
|
|
|
|
|
As my other reply said, you don't recreate all this functionality. There is a wrapper TreeViewItem always created for you whether you like it or not . Well, there is a way to override that, but that's beyond the scope of this thread.
|
|
|
|
|
Hello,
My WPF application (WpfApplication1) is, for its XAML part, composed of an single empty grid.
Elements are loaded inside this grid from an external XAML file, read through XamlReader.
This external Xaml file contains (for the purpose of this example) a URL to an image which should be located in the 'My documents' user folder.
The problem is that during importation the url from images should be relative to the application which is loading the file!
In other words, this URL should be relative to the application (pack://siteoforigin:, pack://application)
...and in my case, this path is 'outside' from that context and should be built this way:
Environment.GetFolderPath(Environment.SpecialFolde r.MyDocuments) & "Theme\"
So, I wrote a Converter, hoping to build the complete path url...but without succes!!
> 'Impossible to create the unknow type '{clr-namespace:WpfApplication1}imgurlConvert'.'
The application XAML part:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:local="clr-namespace:test"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Class="MainWindow" Title="main" Height="600" Width="800">
<Grid></Grid>
</Window>
The application VB part:
Imports System.IO
Class MainWindow
Public Shared ThemeTempFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\Theme\"
Public Shared themeGrid As Grid
Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
Debug.Print(ThemeTempFolder)
loadInterface()
End Sub
Sub loadInterface()
Dim GridUri As String = ThemeTempFolder & "theme.xaml"
Dim fs As FileStream = New FileStream(GridUri, FileMode.Open, FileAccess.Read)
Dim sri = TryCast(System.Windows.Markup.XamlReader.Load(fs), Grid)
Me.Content = sri
fs.Close()
themeGrid = LogicalTreeHelper.FindLogicalNode(sri, "themeGrid")
End Sub
End Class
Public Class imgurlConvert
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Dim valConv As String = MainWindow.ThemeTempFolder & value
If File.Exists(valConv) Then
Return valConv
End If
Return Nothing
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Return value
End Function
End Class
The XAML file to load:
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:local="clr-namespace:WpfApplication1" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib" Name="themeGrid">
<Grid.Resources>
<local:imgurlConvert x:Key="urlConvert" />
</Grid.Resources>
<Grid Name="mainGrid">
<Image Source={Binding Path="image.png", Converter={StaticResource urlConvert}} CacheOption="OnLoad" x:Name="Image1"/>
</Grid>
</Grid>
I hope that I was clear enough!? Thanks for helping me!!
|
|
|
|
|
How can we integrate HTML Help files with Table Of Contents into an application developing in C#.NET.
While installing the application (.exe), the help files also should get extracted into the installation folder and when the user press F1 key or click on the Help Icon/ link, the index.htm page should display in a browser.
Please note that the html files are having CSS, Images, and Scripts in separate folders.
Kind regards, Adarsh
|
|
|
|