Changing the Toolbox style in Windows re-hosted workflow designer - c#

Using AvalonDock I created the ToolBoxControl and now I am planning to disable certain top level activities (want it visible just greyed out). I wanted to know the ways I can do it.
The image below, the activities circled in red, I want either to grey them out or change font colour. This way I can differentiate the users using the software.
The code used for this in XAML is
<xcad:DockingManager Grid.Row="1"
AllowMixedOrientation="True"
BorderBrush="Black"
BorderThickness="1">
<xcad:LayoutRoot x:Name="LayoutRoot">
<xcad:LayoutPanel Orientation="Horizontal">
<xcad:LayoutAnchorablePane DockWidth="200">
<xcad:LayoutAnchorable Title="Toolbox" CanClose="False" CanFloat="False" CanHide="False" ContentId="toolbox" x:Name="CtrlToolbox">
</xcad:LayoutAnchorable>
<xcad:LayoutAnchorable Title="Outline" CanClose="False" CanFloat="False" CanHide="False" ContentId="outline" x:Name="CtrlOutline">
</xcad:LayoutAnchorable>
</xcad:LayoutAnchorablePane>
The .cs version of this is :
private void AddToolBox()
{
ToolboxControl tc = GetToolboxControl(); //CreateToolboxControls();
CtrlToolbox.Content = tc;
}
private ToolboxControl GetToolboxControl()
{
// Create the ToolBoxControl.
ToolboxControl ctrl = new ToolboxControl();
ToolboxCategory categoryFlowChart = new ToolboxCategory("Flow Chart");
ToolboxCategory categoryStateMachine = new ToolboxCategory("State Machine");
ToolboxCategory categoryExport = new ToolboxCategory("File System");
ToolboxCategory categoryWindowsApp = new ToolboxCategory("Windows App");
ToolboxCategory categorySSH = new ToolboxCategory("SSH");
ToolboxCategory categoryVBScript = new ToolboxCategory("VB Script");
ToolboxCategory categoryCommunication = new ToolboxCategory("Communication");
ToolboxCategory categoryDatabase = new ToolboxCategory("Database");
// Add the category to the ToolBox control.
ctrl.Categories.Add(categoryFlowChart);
ctrl.Categories.Add(categoryDatabase);
ctrl.Categories.Add(categoryStateMachine);
ctrl.Categories.Add(categoryWindowsApp);
ctrl.Categories.Add(categorySSH);
ctrl.Categories.Add(categoryCommunication);
ctrl.Categories.Add(categoryVBScript);
return ctrl
}
Any other information I need to provide please let me know. Just need to be able to disable the top level activity.

Take a look at this example, its not exactly what your after. But it explains how to customize the ToolboxControl style and alter the icons. The idea can be applied to alter the style of the ToolboxItems to your own means. (review step 3 specifically). If you need further assistance I can work on an example.

Related

xceed avalonDock FloatingWindows it must be dockable on more DockingManager

"I have two or more dockingManager, and I want every FloatingWindows to be dockable on every dockingManager."
floatingWindows must be created within a dockingManager, but it must be possible to dock it into another separate docking manager.
so when I do drag inside the first dockingManager the default positions are displayed. (4 icons: top, left, bottom, right)
but when I drag the floatingWindows into the second dockingManager nothing appears.
<Grid>
<avalonDock:DockingManager x:Name="dock1" Width="300" Height="200">
<avalonDockLayout:LayoutRoot>
<avalonDockLayout:LayoutRoot.FloatingWindows>
<avalonDockLayout:LayoutAnchorableFloatingWindow>
<avalonDockLayout:LayoutAnchorablePaneGroup DockHeight="100" DockWidth="100">
<avalonDockLayout:LayoutAnchorablePane x:Name="_LayoutAnchorablePane" FloatingHeight="150" FloatingWidth="150">
<avalonDockLayout:LayoutAnchorableTitle="FloatingWindow">
<Grid Background="CornflowerBlue">
</Grid>
</avalonDockLayout:LayoutAnchorable>
</avalonDockLayout:LayoutAnchorablePane>
</avalonDockLayout:LayoutAnchorablePaneGroup>
</avalonDockLayout:LayoutAnchorableFloatingWindow>
</avalonDockLayout:LayoutRoot.FloatingWindows>
</avalonDockLayout:LayoutRoot>
</avalonDock:DockingManager>
<avalonDock:DockingManager x:Name="dock2" Width="300" Height="200" >
<avalonDockLayout:LayoutRoot>
</avalonDockLayout:LayoutRoot>
</avalonDock:DockingManager/>
I also tried to force it from code, but it does not work!
LayoutAnchorable mAnchorableChilder=null;
public MainWindow()
{
InitializeComponent();
mAnchorableChilder = new LayoutAnchorable();
mAnchorableChilder.Title = "Sample dynamic avalondock";
_LayoutAnchorablePane.Children.Add(mAnchorableChilder);
Grid grid = new Grid { Background = new SolidColorBrush(Colors.Green) };
mAnchorableChilder.Content = grid;
}

UserControl hidden, Zindex misused?

In my main page I try to show a list of stuff, and on this stuff a userControl as an overlay. In fact I never see it. (In the design view, my userControl is oaky)
XAML MainPage
<Grid>
<Grid x:name="MyPage">
<!-- All this part is visible -->
//Button
//Button
//nice Pic
//Button
</Grid>
<cat:CatPagecontrol x:Name="CatTool" Visibility="Visible" HorizontalAlignment="Center" VerticalAlignment="Center">
<cat:CatPagecontrol.Transitions>
<TransitionCollection>
<PopupThemeTransition/>
</TransitionCollection>
</cat:CatPagecontrol.Transitions>
</cat:CatPagecontrol>
<!-- EDIT I remove the Grid "CatGrid" And the ZIndex -->
</Grid>
I try to switch the ZIndex, no results.
C# File
public MainView()
{
this.CatTool = new CatPagecontrol();
//this.CatTool.Visibility = Visibility.Collapsed;
}
private void showCatSelector()
{
this.CatTool.Visibility = Visibility.Visible;
}
After that I need that one of my buttons show the overlay when clicked.
If you know how to show it, I'm yours. Thanks.
edit : solution find.
Voila !
I've find my problem :
public CatPagecontrol()
{
this.InitializeComponent();
}
I just Initialized in the correct section.

Printing UI: Specified Visual is already a child of another Visual or the root of a CompositionTarget

So I built a WYSIWYG editor that allows users to drag and drop controls on a canvas. Then, after having it arranged how they'd like, they can print the template out.
I am running into some issues with the Visual tree though.
XAML
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=".2*"/>
<ColumnDefinition Width=".8*"/>
</Grid.ColumnDefinitions>
<StackPanel AllowDrop="False" Background="Gray">
<!--REMOVED-->
</StackPanel>
<Canvas Grid.Column="1" AllowDrop="True" Width="600" Height="800"
Background="White" x:Name="CanvasControl"
DataContext="{Binding CanvasVM}"
DragEnter="CanvasFlowDocument_DragEnter"
DragLeave="CanvasFlowDocument_DragLeave"
DragOver="CanvasFlowDocument_DragOver"
Drop="CanvasFlowDocument_Drop"/>
</Grid>
C#
private void PrintCanvas()
{
//Prompt for print
PrintDialog pd = new PrintDialog();
if (pd.ShowDialog()==true)
{
//Trying to use flow document for printing because I need to be able to control
//how the margins look on the page
FlowDocument CanvasFlowDocument = new FlowDocument();
BlockUIContainer buiCont = new BlockUIContainer();
//Get the parent of the CanvasControl because I can't pass the CanvasControl to my
//Printer until it doesn't have a logical visual parent
Grid par = (Grid)CanvasControl.Parent;
par.Children.Remove(CanvasControl);
//Add Control to Block UI Container for printing
buiCont.Child = CanvasControl;
CanvasFlowDocument.Blocks.Add(buiCont);
//Print the doc
pd.PrintDocument((CanvasFlowDocument as IDocumentPaginatorSource).DocumentPaginator, "Template");
//Now, in an attempt to re-add my canvas to the grid so my user can continue to see/manipulate it. I first clear the blocks
CanvasFlowDocument.Blocks.Clear();
//I even go as far as setting the Block UI Container child to null
buiCont.Child = null;
CanvasControl.UpdateLayout();
//This is where explosions ensue...
//The CanvasControl.Parent is null at this point, yet I still get the error below
par.Children.Add(CanvasControl);
}
}
ERROR:
Specified Visual is already a child of another Visual or the root of a
CompositionTarget
What I found out is that it's possible to have Parent property be NULL, but component is clearly attached to some Visual. In this case you need to use var parentObject = VisualTreeHelper.GetParent(child);, which will reliably tell you visual parent. You can simply use the following snippet:
var parentObject = VisualTreeHelper.GetParent(child);
if (parentObject != null)
{
parentObject.Children.Remove(child);
}

wpf display of textblock based on xml data

I'm developing a kind of Store or something, where I read an RSS Feed and display its content in a ListBox. The RSS Feed contains additional data (for example "download" or "customCategory") that I use (or want to use) to sort the results of the ListBox. The ListBox looks like this:
<ListBox Grid.Column="2" HorizontalAlignment="Stretch" Name="ItemsListParent" VerticalAlignment="Stretch" Margin="0,25,0,0">
<ItemsControl Name="ItemsList" ItemsSource="{Binding Source={StaticResource rssData}}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Name="itemElement" Orientation="Horizontal" Loaded="itemElement_Loaded">
<StackPanel.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="White" Offset="0.15" />
<GradientStop Color="LightGray" Offset="0.85" />
<GradientStop Color="White" Offset="1" />
</LinearGradientBrush>
</StackPanel.Background>
<!--<Image Width="15" Margin="2" Source="{Binding XPath=url, Path=InnerText}"/>-->
<!--<TextBlock Margin="2" FontSize="16" VerticalAlignment="Center" Text="{Binding XPath=title}" FontWeight="Normal">
<Hyperlink Name="lnkGoToArticle" Tag="{Binding XPath=link, Path=InnerText}" Click="lnkGoToArticle_Click">
>>
</Hyperlink>
<Button Name="lnkDownload" Tag="{Binding XPath=download, Path=InnerText}" Style="{DynamicResource NoChromeButton}" Click="lnkDownload_Click">
<Image Source="Images/download31.png" Name="DownloadIcon" Width="30" Height="30" />
</Button>
</TextBlock>-->
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ListBox>
the code in
<!-- -->
is what I rewrote to C#, as I thought I can figure out how to sort the XML. The point is, that I've created
void UpdateListBox()
{
ItemsList.Items.Clear();
selected = (string)CategoriesList.SelectedItem;
//if (selected==xmldp
/*System.Xml.XmlDocument data = new System.Xml.XmlDocument();
data.Load(#"http://www.andystore.bluefile.cz/?feed=rss2");
xmldp.Document = data;
xmldp.XPath = "//item";*/
Thickness mrg = new Thickness();
mrg.Left = 2;
mrg.Right = 2;
mrg.Top = 2;
mrg.Bottom = 2;
TextBlock itemTitle=new TextBlock();
itemTitle.Margin=mrg;
itemTitle.FontSize=16;
itemTitle.VerticalAlignment = VerticalAlignment.Center;
itemTitle.Text = "{Binding XPath=title}";
itemTitle.FontWeight = FontWeights.Normal;
itemTitle.Name="itemTitle";
Binding itemTitleBinding=new Binding();
itemTitleBinding.XPath="title";
itemTitle.SetBinding(TextBlock.TextProperty,itemTitleBinding);
itemElement.Children.Add(itemTitle);
itemElement.RegisterName(itemTitle.Name, itemTitle);
Label gta = new Label();
Hyperlink goToArticle = new Hyperlink();
goToArticle.Click += new RoutedEventHandler(lnkGoToArticle_Click);
goToArticle.Inlines.Add(#">>");
Binding goToArticleBinding = new Binding();
goToArticleBinding.Path = new PropertyPath("InnerText");
goToArticleBinding.XPath = "link";
goToArticle.SetBinding(Hyperlink.TagProperty, goToArticleBinding);
gta.Content = goToArticle;
itemElement.Children.Add(gta);
itemElement.RegisterName(goToArticle.Name, goToArticle);
Button downloadButton = new Button();
downloadButton.Name = "lnkDownload";
downloadButton.Cursor = Cursors.Hand;
downloadButton.Click += new RoutedEventHandler(lnkDownload_Click);
Binding downloadButtonBinding = new Binding();
downloadButtonBinding.XPath = "download";
downloadButtonBinding.Path = new PropertyPath("InnerText");
downloadButton.SetBinding(Button.TagProperty, downloadButtonBinding);
Style downloadButtonStyle = this.FindResource("NoChromeButton") as Style;
downloadButton.Style = downloadButtonStyle;
BitmapImage dbiBitmap = new BitmapImage();
dbiBitmap.BeginInit();
dbiBitmap.UriSource = new Uri("pack://application:,,,/AndyLaunchWPF;component/Images/download31.png");
dbiBitmap.EndInit();
Image dbi = new Image();
dbi.Width = 30;
dbi.Height = 30;
dbi.Name = "downloadIcon";
dbi.Source = dbiBitmap;
downloadButton.Content = dbi;
itemElement.Children.Add(downloadButton);
itemElement.RegisterName(downloadButton.Name, downloadButton);
//itemElement.Children.Add(dbi);
//itemElement.RegisterName(dbi.Name, dbi);
}
but it completes the whole listbox (as before in wpf code) without repeating the calling!! I wanted to add somekind of condition for sorting such as if(xmldp.IDontKnowTheExactName==selectedCategory){display the textblock} else {do not display it and go to next item in XML} but i really dont know how to do it. Please be patient with me, as i am new to WPF and this is also my first question. In the case that you didn't really got what I'm trying to achieve, here is a simple list:
1) I want to load the XML and display all it's items in ItemsList
2) I want to select an item in the ListBox called categoriesList and based on the selection update ItemsList to display only items that have their customCategory==selected (selected is a string that will be updated depending on the categoriesList selection)
Problem is, I dont know where to put the condition, nor how it should look like and if it's even possible.
Hope you understood and you are able to help me.
Thanks for any answer ;) Andy
OK forget constructing the view via code, that's not how WPF is supposed to work. Go back to your original xaml template.
Now the problem you have is that you want to sort and filter the items in the ItemsControl. To do this you need to bind the ItemsSource of the ItemsControl to a CollectionView based on the rssFeed, instead of binding to the rssFeed itself.
CollectionView allows you to easily sort and filter collections.
By the way, you appear to have a redundant ListBox in your XAML. It's not doing anything since you are declaring an ItemsControl inside it. ListBox already derives from ItemsControl.
If you want a scrollbar then just use the ListBox.

stackpanel in datapager silverlight

I am developing a silverlight navigation application and got stuck on the following problem...
The guy I am developing the app wants to have a News page where you can see all published news on the left side and the clicked (or latest news if none is clicked) on the right side. He wanted to have a header, text and publishing date for each news in the news list. Also he wanted to have paging so that there won't be to many news in the list at once...
I did this:
foreach (Model.News news in s)
{
StackPanel stackPanel = new StackPanel();
HyperlinkButton hyperlinkButton = new HyperlinkButton();
hyperlinkButton.Tag = news.Header;
hyperlinkButton.Content = news.Header;
hyperlinkButton.FontSize = 15;
hyperlinkButton.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
hyperlinkButton.Click += new RoutedEventHandler(Button_Click);
stackPanel.Children.Add(hyperlinkButton);
TextBlock textBlock = new TextBlock();
textBlock.Foreground = new SolidColorBrush(Colors.Gray);
textBlock.FontSize = 12;
textBlock.FontFamily = new FontFamily("Verdana");
textBlock.TextWrapping = TextWrapping.Wrap;
textBlock.Text = news.Text;
stackPanel.Children.Add(textBlock);
TextBlock dateTextBlock = new TextBlock();
dateTextBlock.Foreground = new SolidColorBrush(Colors.Gray);
dateTextBlock.FontSize = 10;
dateTextBlock.FontFamily = new FontFamily("Verdana");
dateTextBlock.TextWrapping = TextWrapping.Wrap;
dateTextBlock.FontWeight = FontWeights.Bold;
dateTextBlock.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
dateTextBlock.Text = news.Date.ToShortDateString();
stackPanel.Children.Add(dateTextBlock);
stackPanel.Children.Add(new TextBlock());
newsStackPanel.Children.Add(stackPanel);
}
PagedCollectionView itemListView = new PagedCollectionView(newsStackPanel.Children);
newsPager.Source = itemListView;
and all of it goes here
<Grid x:Name="LayoutRoot" Loaded="LayoutRoot_Loaded" MaxWidth="1100">
<Grid.RenderTransform>
<CompositeTransform/>
</Grid.RenderTransform>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="2"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<RichTextBox Name="contentRTB" MaxWidth="1000" Margin="10, 30, 10, 30" Grid.Column="2"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
TextWrapping="Wrap"
Style="{StaticResource RichTextBoxStyle}" IsReadOnly="True"/>
<Rectangle Grid.Column="1" Margin="0,10"
Fill="#FF0067C6"/>
<TextBlock Name="header" Foreground="#FF0067C6" FontSize="18" FontFamily="Verdana" HorizontalAlignment="Center" VerticalAlignment="Top" Grid.Column="0"></TextBlock>
<sdk:DataPager x:Name="newsPager"
DisplayMode="FirstLastNumeric"
Background="#FF0067C6"
PageSize="3"
AutoEllipsis="True"
NumericButtonCount="3"/>
<StackPanel Name="newsStackPanel" Grid.Column="0" Orientation="Vertical" Margin="0,50,0,0"/>
</Grid>
The newsPager displayes (correctly) 2 pages because i have currently 5 news and the pageSize is set to 3 but they are all displayed on the same page so I dont get the desired paging... how can i fix it
Your code is adding all the items to a StackPanel, then it is putting that StackPanel inside another StackPanel called "newsStackPanel" below the DataPager. So, right now, the DataPager has nothing to do with the display of your news articles, and you won't be seeing any paging happening.
Instead, take a look at the DataPager sample code here:
http://msdn.microsoft.com/en-us/library/system.windows.controls.datapager(VS.95).aspx#Y9406
You'll need to modify that sample code to contain a list of StackPanels like this:
List<StackPanel> itemList = new List<StackPanel>();
Then, for each of your news items, add them to that list instead of an outer StackPanel:
itemList.Add(stackPanel);
You'll then wrap that up and bind it to both your data pager and a new list control:
// Wrap the itemList in a PagedCollectionView for paging functionality
PagedCollectionView itemListView = new PagedCollectionView(itemList);
// Set the DataPager and ListBox to the same data source.
newsPager.Source = itemListView;
listBox1.ItemsSource = itemListView;
The sample uses a ListBox called "listBox1". You have lots of choices there. Perhaps replace the "newsStackPanel" with a ListBox called "newsList".
OK, that should be enough to get you through this.
Now for a little more homework:
You should really consider switching this to the MVVM pattern where you bind these values and template them instead of making UI controls in C#. This results in much cleaner code, enables much easier reuse, improves testability, and so on. There are a million zillion articles on the web for this. Here is one from MS:
http://msdn.microsoft.com/en-us/library/gg430869(v=PandP.40).aspx
I don't know if the DataPager control you're using handles the paging completely.
You could only add the news items that are on the page you want to view to the stack panel.
One easy way to do that could be to use LINQ in your for each, something like:
foreach (Model.News news in s.Skip(newsPager.PageSize * newsPager.PageIndex).Take(newsPager.PageSize))
you'd have to reinitialize the items in the pager when the page index changes then too.

Categories

Resources