I'm trying to change the property materialDesign:ButtonProgressAssist.IsIndeterminate via C# code.
I haven't found any property like that in the Button object.
This is the buttons code:
<Button x:Name="loginButton" VerticalAlignment="Bottom" HorizontalAlignment="Center" Margin="0,0,0,100" Width="100"
Style="{StaticResource MaterialDesignRaisedButton}"
materialDesign:ButtonProgressAssist.Value="-1"
materialDesign:ButtonProgressAssist.IsIndicatorVisible="True"
materialDesign:ButtonProgressAssist.IsIndeterminate="false" />
I want to set the IsIndeterminate Property to true when it gets clicked.
I don't understand, why i always find it out shortly after i ask it on StackOverflow...
But here's the solution:
MaterialDesignThemes.Wpf.ButtonProgressAssist.SetIsIndeterminate(loginButton, true);
Related
I'm trying to programatically create a button flyout, within my XAML I have:
<Page.Resources>
<Button x:Key="LaunchFlyout" Content="LAUNCH">
<Button.Flyout>
<Flyout Placement="Top">
<Grid Width="200" Height="200">
<StackPanel>
<Rectangle Fill="Red" Width="100" Height="100" />
<Rectangle Fill="Green" Width="100" Height="100" />
</StackPanel>
</Grid>
</Flyout>
</Button.Flyout>
</Button>
</Page.Resources>
Nested within grids I have:
<Grid x:Name="launchBtn_grid" Grid.Column="1">
</Grid>
And then in my code within the Page_Loaded method I have:
bool hasContainer = localSettings.Containers.ContainsKey("appStatus");
if (!hasContainer) {
Button button = (Button)this.Resources["LaunchFlyout"];
launchBtn_grid.Children.Add(button);
}
else {
Button button = new Button();
button.Content = "LAUNCH";
button.Click += launch_btn_Click;
launchBtn_grid.Children.Add(button);
}
When I debug this, it reaches the IF statement and reaches this line launchBtn_grid.Children.Add(button); and then I get this error Element is already the child of another element.
Does anyone understand why? I have already looked and they dont already exist so I don't understand why it is giving me this error. Does anyone know what I am doing wrong?
I'm not sure in what context/use case your are doing that, but it feels weird to me to have an actual control as a Resource (not a DataTemplate, Style, etc).
If you only want to have 1 button of the 2 different template, why not switch Visibility on the 2 instead of loading controls from your code behind ?
Going forward with the idea, just add both buttons in the Grid within your XAML and switch their Visibility according to the setting you read.
There is a BooleanToVisibilityConverter within the framework to help you with this.
I need to create a button with two lines of text:
The first one is Command Title like "Save"
The second one is a Description of the Command like "The application state will be saved"
So I have written the next xaml:
<Button Margin="0,128,0,0" Padding="10,5" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<StackPanel Margin="0" UseLayoutRounding="False">
<TextBlock FontSize="{StaticResource PhoneFontSizeMediumLarge}" FontFamily="{StaticResource PhoneFontFamilySemiBold}">Save</TextBlock>
<TextBlock Style="{StaticResource PhoneTextSubtleStyle}" Margin="0">The application state will be saved</TextBlock>
</StackPanel>
</Button>
This code working well except a one issue. The Description line becomes invisible when the button is pushed.
I'm sure the root cause is the low contrast color of the description line. But I don't know how to fix it.
Update: I have tried to use the PhoneTextSubtleStyle style but still have the same issue.
You could retemplate the Button (using the Control.Template property) to look different so that when pushed it no longer interferes with the content.
Could you try something like this
System.Windows.Visibility.Visible;
System.Windows.Visibility.Hidden;
or
System.Windows.Visibility.Collapsed
here is a link that will show an example of how to use this inside of a StackPanel
How to: Change the Visibility Property
<TextBox Foreground="Black"
FontFamily="Times New Roman"
FontWeight="Bold"
FontSize="15"
MaxHeight="50"
Margin="6,95,40.067,0"
Name="txt1" VerticalAlignment="Top"
IsHitTestVisible="False"
Height="30"
Grid.Row="4"
Grid.Column="2"/>
What is the role of IsHitTestVisible property on TextBox?
When you have a control inside another control, like, If you have a TextBox inside... lets say, another TextBox. Then by setting the isHitTestvisible property of the parent control to False you allow the user to type in the child TextBox. If you set it to True then the RoutedEvent will be handled at the parent control level.
This property is mostly used when you work with Adorners.
Check this posts
http://social.msdn.microsoft.com/Forums/en/wpf/thread/7c352827-b4ed-493c-8a68-58179ad801fc
http://msdn.microsoft.com/en-us/library/system.windows.uielement.ishittestvisible.aspx
true if this element could be returned as a hit test result from at least one point; otherwise, false. The default value is true.
Source: MSDN
See also: Hit Testing in the Visual Layer
Please forgive this stupid question. (I'm originally an ASP.NET programmer.)
I'm trying to add a telerik context menu to a textbox control in the code behind.
Adding it in the xaml is very easy (this works)
<TextBox AcceptsReturn="True" Text="{Binding Mode=TwoWay, Path=Description}" TextWrapping="Wrap" x:Name="txtIssues" Width="280" Height="100" VerticalScrollBarVisibility="Auto">
<telerikNavigation:RadContextMenu.ContextMenu>
<telerikNavigation:RadContextMenu x:Name="contextMenu"
ItemClick="ContextMenuClick">
<telerikNavigation:RadMenuItem Header="Set Vista as Background" />
<telerikNavigation:RadMenuItem Header="Set Beach as Background" />
<telerikNavigation:RadMenuItem Header="Set Forest as Background" />
</telerikNavigation:RadContextMenu>
</telerikNavigation:RadContextMenu.ContextMenu>
</TextBox>
However I would like to completely add the the control from c# code and I can't find a why to add a control to a textbox. I've been looking for something like "txtIssues.Children.Add" but there doesn't seem to be an option.
First its best you understand that you are not adding a control to the TextBox. The RadContextMenu.ContextMenu is not a control it is an attached property.
Funnily enough the Telerik documentation describes adding a context menu to a textbox in C#. See Working with the RadContextMenu. Sometimes "RTM" is actually good advice.
I have a custom component, ExportCommandButton, that has two attached properties. This component is designed to be attached to a button. When clicked, the component would initiate the export method of the grid (Telerik RadGridView). The problem I have is how can I pass the grid to the component via one of the attached properties? I've tried element to element binding, but the GridView set property never fires. How do you bind to a control and not a property of the control?
<Button IsEnabled="{Binding Loaded}"
cmd:ExportCommandButton.GridView="{Binding ElementName=MyGrid}"
cmd:ExportCommandButton.Converter="{StaticResource MyConverter}">
<Button.Content>
<StackPanel Orientation="Horizontal">
<Image Source="/Assets/xls.png" />
<TextBlock VerticalAlignment="Center" Text="Export" Margin="5,0,0,0" />
</StackPanel>
</Button.Content>
</Button>
Your syntax seems right. The CLR property setter is not called because the binding directly updates the dependency property, without passing by the property which is here for convenience. Use the propertyChangedCallback parameter of your attached property metadata to listen for changes.