how to remove radwindow confirm title bar and icon - c#

I am looking for a pure radwindow confirm dialog which only keeps Content and YesNoButton. I didn't find any properties to switch those off. How can I do this? I tried this :
public void ShowConfirm()
{
RadWindow.Confirm(new DialogParameters()
{
Header = "",
Content = new TextBlock()
{
MaxWidth = 200,
Background = new SolidColorBrush(Colors.Red),
Foreground = new SolidColorBrush(Colors.Black),
TextWrapping = TextWrapping.Wrap,
Text = "Test",
FontSize = 24
},
Closed = OnClosed,
WindowStyle = this.Resources["ConfirmDialog"] as Style
});
}
private void OnClosed(object sender, WindowClosedEventArgs e)
{
var result = e.DialogResult;
if (result == true)
{
//
}
}
<Style x:Key="checkWeekDialog" TargetType="telerik:RadWindow">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Width" Value="400"/>
<Setter Property="Background" Value="Yellow"/>
<Setter Property="MinHeight" Value="300"/>
<Setter Property="Icon" Value=""/>
<!--<Setter Property="WindowStartupLocation" Value="CenterOwner"/>-->
<Setter Property="SnapsToDevicePixels" Value="True"/>
</Style>

One way to hide the titlebar of the RadConfirm component is via the VisibleTitlebar property of the RadWindowManager:
Another way is via CSS and this class:
.rwTitlebarControls {
display: none !important;
}

Related

How to Convert XAML to c#?

I'm using accordion control.
<dxa:AccordionControl.Resources>
<Style TargetType="dxa:AccordionItem">
<Setter Property="Foreground" Value="Orange"/>
<Style.Triggers>
<Trigger Property="IsMouseOverHeader" Value="True">
<Setter Property="Foreground" Value="black"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="Black"/>
</Trigger>
</Style.Triggers>
</Style>
</dxa:AccordionControl.Resources>
But I don't use it anymore ↑
because I changed the contents of the item dynamically.
Setter setter = new Setter();
Style style2 = new Style();
style2.TargetType = new AccordionItem().GetType();
setter.Property = AccordionItem.ForegroundProperty;
setter.Value = Brushes.Red;
style2.Setters.Add(setter);
ResourceDictionary resourceDictionary = new ResourceDictionary();
resourceDictionary.Add(style2.TargetType, style2);
//Trigger trigger = new Trigger();
//trigger.Property = AccordionItem.IsMouseOverHeaderProperty;
//trigger.Value = true;
accordionControlHistoryMenu.Resources = resourceDictionary;
How Can I express it this xamlcode convert xaml to C# source?
You don't need to store the style in a ResourceDictionary, just assign it directly:
Xaml:
<dxa:AccordionControl.Resources x:Name="myControl">
Code:
myControl.Style = style2;
While this answers your question, it's almost never the correct way to do this. Your styles should be binding to dynamic data that your view model layer is creating.

DataGridHyperlinkColumn text color when highlighted

I have a simple WPF application which displays reddit links in a DataGrid:
Notice however that the link in the DataGridHyperlinkColumn isn't visible when a row is selected, due to the color of the link and the color of the row highlight.
What's a good way to resolve this? Change the link text color? Change the row highlight color?
If possible, please show your suggestion in terms of C# code as opposed to XAML as this application isn't using XAML. Otherwise, a XAML solution is fine; I'll just convert it to C#. :-)
For reference, here's the code used for the Title column:
var event_setter = new EventSetter()
{
Event = Hyperlink.ClickEvent,
Handler = (RoutedEventHandler)((sender, e) =>
{
System.Diagnostics.Process.Start((data_grid.SelectedItem as Link).Url);
})
};
var style = new Style();
style.Setters.Add(event_setter);
var hyperlink_column = new DataGridHyperlinkColumn()
{
Header = "Title",
Binding = new Binding("Title"),
ElementStyle = style,
Width = 600
};
data_grid.Columns.Add(hyperlink_column);
You could add an implicit Hyperlink style to your DataGrid:
const string Xaml = "<Style TargetType=\"Hyperlink\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">" +
"<Style.Triggers>" +
"<DataTrigger Binding=\"{Binding IsSelected, RelativeSource={RelativeSource AncestorType=DataGridCell}}\" Value=\"True\">" +
"<Setter Property=\"Foreground\" Value=\"White\" />" +
"</DataTrigger>" +
"</Style.Triggers>" +
"</Style>";
data_grid.Resources.Add(typeof(Hyperlink), System.Windows.Markup.XamlReader.Parse(Xaml) as Style);
data_grid.Columns.Add(hyperlink_column);
The Selector.IsSelected property of DataGridHyperLink Column can be used and when the selection on particular item changes you can update the style with trigger.
<DataGridHyperlinkColumn.CellStyle>
<Style TargetType="{x:Type Hyperlink}">
<Setter Property="Foreground" Value="Blue"/>
<Style.Triggers>
<Trigger Property="Selector.IsSelected" Value="True">
<Trigger.Setters>
<!--change the value for the property based on your needs-->
<Setter Property="Foreground" Value="Yellow"/>
</Trigger.Setters>
</Trigger>
</Style.Triggers>
</Style>
</DataGridHyperlinkColumn.CellStyle>
Pure XAML solution:
<DataGrid>
<DataGrid.Resources>
<Style TargetType="{x:Type Hyperlink}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=DataGridCell}}"
Value="True">
<DataTrigger.Setters>
<Setter Property="Foreground" Value="Yellow"/>
</DataTrigger.Setters>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridHyperlinkColumn Width="180"
Header="Url"
Binding="{Binding Path=Uri, Mode=OneWay}" />
</DataGrid.Columns>
</DataGrid>
Here's a version of the answer provided by #mm8 converted from XAML to C#:
var data_trigger = new DataTrigger()
{
Binding = new Binding()
{
Path = new PropertyPath("IsSelected"),
RelativeSource = new RelativeSource() { AncestorType = typeof(DataGridCell) }
},
Value = true
};
data_trigger.Setters.Add(new Setter(ForegroundProperty, new SolidColorBrush(Colors.White)));
var style = new Style(typeof(Hyperlink));
style.Triggers.Add(data_trigger);
data_grid.Resources.Add(typeof(Hyperlink), style);
Here's a version of the answer provided by #mm8 converted from XAML to C# which uses some extension methods to avoid intermediate variables:
data_grid.Resources.Add(
typeof(Hyperlink),
new Style(typeof(Hyperlink))
.AddTrigger(
new DataTrigger()
{
Binding = new Binding()
{
Path = new PropertyPath("IsSelected"),
RelativeSource = new RelativeSource() { AncestorType = typeof(DataGridCell) }
},
Value = true
}
.AddSetter(new Setter(ForegroundProperty, new SolidColorBrush(Colors.White)))));

Getting binding expressions from code behind from Datatemplate Triggers

I've been set to maintain a wpf application where there is a listbox for logging purposes.
The items displayed using listbox are of type TextMessage, i.e. the listbox is bound to these text messages via
ObservableCollection<TextMessage> Messages;
listBox.DataContext = Messages;
Messages are then added with something like
Messages.Add(new TextMessage("Test", TypeOfMessage.Headline));
This is the definition of the class TextMessage
public enum TypeOfMessage
{
Normal,
Headline,
Focus,
Important,
Fail,
Success
}
public class TextMessage
{
public TextMessage(string content, TypeOfMessage typeOfMessage)
{
Content = content;
TypeOfMessage = typeOfMessage;
CreationTime = DateTime.Now;
}
public string Content { get; }
public TypeOfMessage TypeOfMessage { get; }
public DateTime CreationTime { get; }
}
The xaml definition for the listbox is something like this:
<ListBox x:Name="listBox" HorizontalAlignment="Left" Height="196" Margin="101,77,0,0" VerticalAlignment="Top" Width="256" ItemsSource="{Binding}" SelectionMode="Multiple">
<ListBox.InputBindings>
<KeyBinding
Key="C"
Modifiers="Control"
Command="Copy"
/>
</ListBox.InputBindings>
<ListBox.CommandBindings>
<CommandBinding
Command="Copy"
Executed="DoPerformCopy"
/>
</ListBox.CommandBindings>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock x:Name="TextToShow" Text="{Binding Content}"></TextBlock>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding TypeOfMessage}" Value="Normal">
<Setter TargetName="TextToShow" Property="Foreground" Value="Black"/>
</DataTrigger>
<DataTrigger Binding="{Binding TypeOfMessage}" Value="Focus">
<Setter TargetName="TextToShow" Property="Foreground" Value="Black"/>
<Setter TargetName="TextToShow" Property="FontWeight" Value="Bold"/>
</DataTrigger>
<DataTrigger Binding="{Binding TypeOfMessage}" Value="Headline">
<Setter TargetName="TextToShow" Property="Foreground" Value="RoyalBlue"/>
<Setter TargetName="TextToShow" Property="FontWeight" Value="Bold"/>
</DataTrigger>
<DataTrigger Binding="{Binding TypeOfMessage}" Value="Important">
<Setter TargetName="TextToShow" Property="Foreground" Value="Red"/>
</DataTrigger>
<DataTrigger Binding="{Binding TypeOfMessage}" Value="Fail">
<Setter TargetName="TextToShow" Property="Foreground" Value="Red"/>
<Setter TargetName="TextToShow" Property="FontWeight" Value="Bold"/>
</DataTrigger>
<DataTrigger Binding="{Binding TypeOfMessage}" Value="Success">
<Setter TargetName="TextToShow" Property="Foreground" Value="Green"/>
<Setter TargetName="TextToShow" Property="FontWeight" Value="Bold"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
This works nicely (i.e messages are displayed in the listbox in different font weight and color depending on their type), but now for the question :
Is there any way using BindingExpression or any other means to get the font formatting and coloring from code behind from the xaml definitions ?
The reason is that I want to just have the formatting in one place (just in the xaml as it is right now) but still be able to reuse it when I want to copy the contents (using code behind) including font formatting to the clipboard.
Example:
private void DoPerformCopy()
{
RichTextBox rtb = new RichTextBox();
foreach (TextMessage message in (listBox as ListBox)?.SelectedItems.Cast<TextMessage>().ToList())
{
TextPointer startPos = rtb.CaretPosition;
rtb.AppendText(message.Content);
rtb.Selection.Select(startPos, rtb.CaretPosition.DocumentEnd);
//
// Here it would be very nice to instead having multiple switch statements to get the formatting for the
// TypeOfMessage from the xaml file.
SolidColorBrush scb = new SolidColorBrush(message.TypeOfMessage == TypeOfMessage.Fail ? Colors.Red);
//
rtb.Selection.ApplyPropertyValue(RichTextBox.ForegroundProperty, scb);
}
// Now copy the whole thing to the Clipboard
rtb.Selection.Select(rtb.Document.ContentStart, rtb.Document.ContentEnd);
rtb.Copy();
}
Since I'm new to wpf, I'd really appreciate if someone has a tip for solving this. (I've tried hard to find an solution here at stackoverflow, but so far I've been unsuccessful)
Thanks in advance,
King regards
Magnus
Make a ContentPresenter with Content set to your TextMessage. Set the ContentTemplate to listBox.ItemTemplate and apply the template. It will create the visuals (TextBlock in this case). Then, just parse off the values from the TextBlock.
Also, your RichTextBox selection code wasn't working quite right so I fixed that by just inserting TextRanges to the end of it instead of trying to get the selection right.
private void DoPerformCopy(object sender, EventArgs e)
{
RichTextBox rtb = new RichTextBox();
foreach (TextMessage message in (listBox as ListBox)?.SelectedItems.Cast<TextMessage>().ToList())
{
ContentPresenter cp = new ContentPresenter();
cp.Content = message;
cp.ContentTemplate = listBox.ItemTemplate;
cp.ApplyTemplate();
var tb = VisualTreeHelper.GetChild(cp, 0) as TextBlock;
var fg = tb.Foreground;
var fw = tb.FontWeight;
var tr = new TextRange(rtb.Document.ContentEnd, rtb.Document.ContentEnd);
tr.Text = message.Content;
tr.ApplyPropertyValue(RichTextBox.ForegroundProperty, fg);
tr.ApplyPropertyValue(RichTextBox.FontWeightProperty, fw);
}
// Now copy the whole thing to the Clipboard
rtb.Selection.Select(rtb.Document.ContentStart, rtb.Document.ContentEnd);
rtb.Copy();
}

WPF Datagrid DataBinding DataView

Pre-Warning sorry WPF new guy here:
I have a DataGrid bound to a DataTable's DefaultView
ResultDataGrid.ItemsSource = resultTable.DefaultView;
I know the column names, and I need to change a column's foreground if another column is 1 (always 0 or 1)
Currently what I have:
private void ResultDataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
if (e.Column.Header.ToString() == "columnName")
{
e.Column.CellStyle = FindResource("columnStyle") as Style;
}
}
and in XAML:
<Window.Resources>
<Style TargetType="DataGridCell" x:Key="columnStyle">
<Setter Property="Foreground" Value="Black"/>
<Style.Triggers>
<DataTrigger Binding="{Binding resultTable, Path={StaticResource otherColumnName}}" Value="1">
<Setter Property="Foreground" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
Where otherColumnName is set in the constructor
public ResultsCustom(DataTable resultclass, CustomQuery query)
{
// Some other stuff
this.Resources.Add("otherColumnName", COLUMN_NAME);
}
The XAML Style seems to not have the correct path, any help would be appreciated!
I'm not sure about this line of code:
Path={StaticResource otherColumnName}
Are you attempting to compare the property "otherColumnName" of the resultTable to see if this is 1? This wouldn't be a static resource, and you could change your binding to:
Path=otherColumnName

Make Ribbon ContextualTabGroups Show When Ribbon Is Minimized

The following is the scenario:
When the ribbon is not minimized, showing a tab linked to a RibbonContextualTabGroup works fine, as visible in the following screenshot.
When the ribbon is minimized, showing a tab linked to a RibbonContextualTabGroup shows the tabs, but not the contextual tab group header, as visible in the following screenshot.
If the ribbon is minimized, but the popup is open, showing a tab linked to a RibbonContextualTabGroup works fine, as visible in the following screenshot. (The popup is not visible, but that is how I created the scenario.)
WebMatrix also has this problem, so I am assuming that Microsoft developers intentionally coded in this functionality. In Windows 8/Office 2013, however, the contextual tab groups always show, regardless of the state of the ribbon.
I am using the .NET 4.0 RibbonControlsLibrary from Microsoft, so I have access to the full source code. How can I modify the code to force the contextual tab groups to always show, regardless of the state of the ribbon?
Yes, really good, thank you very much, Ming!
Is there a way to use RibbonContextualTabGroupItemsControl.cs without copying and overriding all relating ribbon-source-classes?
I followed again the approach overriding the ribbon style to avoid this extensive work and was finally successful
There is a trigger that handles the IsMinimized-property of the ribbon:
<Trigger Property="IsMinimized" Value="True">
<Setter Property="Content" TargetName="mainItemsPresenterHost" Value="{x:Null}"/>
<Setter Property="Visibility" TargetName="mainItemsPresenterHost" Value="Collapsed"/>
<Setter Property="Content" TargetName="popupItemsPresenterHost" Value="{Binding ElementName=groupsBorder}"/>
<Setter Property="BorderThickness" TargetName="BackgroundBorder" Value="0,0,0,1"/>
</Trigger>
The content of mainItemsPresenterHost-control is a border named 'groupsBorder' that contains all ribbon tabs. When the IsMinimized-property changes to true, this border is moved to the popup presenter named 'popupItemsPresenterHost'.
An other trigger handles the IsDropDownOpen-property:
<Trigger Property="IsDropDownOpen" Value="True">
<Setter Property="BorderThickness" TargetName="BackgroundBorder" Value="0"/>
/Trigger>
I changed both trigger as follows:
<Trigger Property="IsMinimized" Value="True">
<!--<Setter Property="Content" TargetName="mainItemsPresenterHost" Value="{x:Null}"/>-->
<!--<Setter Property="Visibility" TargetName="mainItemsPresenterHost" Value="Collapsed"/>-->
<Setter Property="Height" TargetName="mainItemsPresenterHost" Value="0"/>
<!--<Setter Property="Content" TargetName="popupItemsPresenterHost" Value="{Binding ElementName=groupsBorder}"/>-->
<Setter Property="BorderThickness" TargetName="BackgroundBorder" Value="0,0,0,1"/>
</Trigger>
<Trigger Property="IsDropDownOpen" Value="True">
<Setter Property="BorderThickness" TargetName="BackgroundBorder" Value="0,0,0,1"/>
<Setter Property="Content" TargetName="mainItemsPresenterHost" Value="{x:Null}"/>
<Setter Property="Content" TargetName="popupItemsPresenterHost" Value="{Binding ElementName=groupsBorder}"/>
</Trigger>
Note that i have replaced the setter of the Visibility-property of the mainItemsPresenterHost-control with the Height-property and set it to '0'.
i have the same problem and have found this workaround.
Override the OnApplyTemplate-method in the window that owns the ribbon to get the RibbonContextualTabGroupItemsControl and set internal field:
Set the IsMinimized-property of the ribbon to true, before setting the visibility to the contextual group to visible, then call UpdateLayout of the RibbonContextualTabGroupItemsControl and reset the IsMinimized-Property of the ribbon to false:
Code
...
RibbonContextualTabGroupItemsControl _ribbonContextualTabGroupItemsControl;
...
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
Ribbon ribbon = this.ribbon;
ribbon.ApplyTemplate();
this._ribbonContextualTabGroupItemsControl = ribbon.Template.FindName("PART_ContextualTabGroupItemsControl", ribbon) as RibbonContextualTabGroupItemsControl;
}
...
void toggleRibbonContextualGroupVisibility()
{
if(this.ribbonContextualGroup.Visibility == Visibility.Collapsed)
{
if (this.ribbon.IsMinimized)
{
this.ribbon.IsMinimized = false;
this.ribbonContextualGroup.Visibility = Visibility.Visible;
this._ribbonContextualTabGroupItemsControl.UpdateLayout();
this.ribbon.IsMinimized = true;
}
else
{
this.ribbonContextualGroup.Visibility = Visibility.Visible;
}
}
else
{
this.ribbonContextualGroup.Visibility = Visibility.Collapsed;
}
}
...
I also have tried to override the RibbonContextualTabGroupItemsControl-class and the Ribbon-style without success.
If there are any other solutions, i am really interested in.
After playing around with the source files for the RibbonControlsLibrary, and just doing hardcore trial-and-error, I found the following solution:
Open RibbonContextualTabGroupItemsControl.cs, located at Microsoft/Windows/Controls/Ribbon, expand the Private Methods #region, and locate the HasTabs function. The code should look something like this:
private bool HasTabs(FrameworkElement container)
{
RibbonContextualTabGroup tabGroupHeader = container as RibbonContextualTabGroup;
if (tabGroupHeader == null ||
!tabGroupHeader.IsVisible)
{
return false;
}
foreach (RibbonTab tab in tabGroupHeader.Tabs)
{
if (tab != null && tab.IsVisible)
{
return true;
}
}
return false;
}
All I added was the following two lines of code:
if (Ribbon.IsMinimized)
return true;
The function should now look like this:
private bool HasTabs(FrameworkElement container)
{
RibbonContextualTabGroup tabGroupHeader = container as RibbonContextualTabGroup;
if (tabGroupHeader == null ||
!tabGroupHeader.IsVisible)
{
return false;
}
if (Ribbon.IsMinimized)
return true;
foreach (RibbonTab tab in tabGroupHeader.Tabs)
{
if (tab != null && tab.IsVisible)
{
return true;
}
}
return false;
}
Run your application, and voíla, the contextual tab groups now show even if the ribbon is minimized.
Note that if you do NOT have access to the ribbon source code, then using zznobody's solution will still work at a pinch.

Categories

Resources