How to show DockPanel in MVVM(WPF)? - c#

I made MVVM application using DevExpress and WPF. To show data NamesView.xaml View will be called in Document Tab Provided by DevExpress. Code is:
void ShowDocument(Int32? key)
{
if(DocumentManagerService == null)
return;
IDocument document = (key != null && key.HasValue) ?
GetDocumentById(key.Value) : null;
if(document == null)
{
document = DocumentManagerService.CreateDocument("NamesView", key, this);
}
document.Show();
}
There is a PanelB in NamesCollectionView.xaml file.How to Show "NamesView.xaml" in Panel(named as PanelB defined in NamesCollectionView.xaml file rather than showing in Document Tab?. When user will Click on Edit or new button, NamesView file will get open in response.I want that this file to show in PanelB.
Note: I f my Question is not clear or if you need some more code to figure it out. Please ask me, i will provide you more detail.

Related

Cannot interact an element because Windows Inspect cannot show that element in question - WinAppDriver + Selenium?

I need an advise from those who have more experience on automating a window desktop application.
I cannot automate a test in a certain form because I believe it cannot be done as Win Inspect cannot really see them. I will show you 2 images below what I meant by this.
this image is an example where I CAN automate the button Close using the following BDD, because Win Inspect can see it.
Scenario Outline: IP120929-00060 - I Check Button
Then Button "Close" Is Displayed
the image below is an example where I CANNOT automate the button Close using the same BDD & test definition (and method), because (I believe) Win Inspect cannot see it (however the properties of that element in question can be viewed)
Scenario Outline: IP99999_DEL_ME-00099 - I Check Button
Then Button "Close" Is Displayed
The Test Definition/Binding for that BDD is:
[Then(#"Button ""(.*)"" Is Displayed")]
public void ThenButtonIsDisplayed(string button)
{
var proc = $"Then Button {button} Is Displayed";
if (CombinedSteps.OutPutProc(proc, OutputLevel.Then))
{
if (Helpers.Button.**Displayed**(button, 3))
{
CombinedSteps.Success();
return;
}
}
CombinedSteps.Failure(proc);
}
public bool **Displayed**(string button, int timeout = 3, string windowName = "")
{
DebugOutput.Log($"Proc - Displayed {button} {timeout} '{windowName}' CurrentPage = {CurrentPage.ToString()}", OutputLevel.Procedure);
if (windowName != "")
{
DebugOutput.Log($"We need to narrow down by window");
return DisplayedByWindow(button, windowName, timeout);
}
var buttonId = CurrentPage.GetElement(button);
if (buttonId == null)
{
DebugOutput.Log($"Did not find a mention of that element in forms Element Factory, ");
return false;
}
var buttonLocator = buttonId.Locator;
DebugOutput.Log($"Find Element by {buttonLocator} ");
if (!JustOneButtonToPress(buttonLocator))
{
var currentPageName = CurrentPage.Name.ToLower();
currentPageName = currentPageName.Replace(" page", "");
var buttonInWindowElement = GetButtonElementInWindow(currentPageName, button);
if (buttonInWindowElement == null)
{
DebugOutput.Log($"Even in window I'm failing to find {button} {currentPageName}");
return false;
}
DebugOutput.Log($"Found in the window - it will click the first that fits under the window");
return buttonInWindowElement.Displayed;
}
DebugOutput.Log($"Got the locator of {buttonLocator}");
var buttonElement = SeleniumUtilities.GetElement(CurrentPage.GetElement(button).Locator, timeout);
if (buttonElement == null)
{
DebugOutput.Log($"Did not find a mention of that element in form");
return false;
}
DebugOutput.Log($"It exists {buttonElement}");
return buttonElement.Displayed;
}
the code will always return buttonElement as null for the Create Curves window form
Its frustrating thing trying to make this works, so my question to know better and have more experience, is this a limitation of the Desktop Application I am testing or is there another way around this? Is it better to ask the Developer to change something about it in the Application?
I have tried to map the 'Close' button in question using it's ID, Name and/or XPath - but all to no avail
any guidance on this would be much appreciated.
Cheers.

Why is TextDecorationCollection always empty in WPF RichTextBox?

I've seen some questions address this problem domain and the unnecessary complexity of handling underlines (mainly applying them, but I want to detect them), but none that I can recall suggesting as I am here that the default strategies for accomplishing this create illogical false negatives. Furthermore, most of the previous questions I've referred to have used a different control (e.g. TextBlock) and/or have obselete syntax.
The problem
(.NET Core 3.1) I would simply like to programatically detect if a WPF RichTextBox selection contains any TextDecorations, but debugging shows that the TextDecorationCollection is always empty, even when the selection is all underlined.
As you can see, TextDecorationCollection returns empty even when examining a fully underlined Inline (Run)
For context, this screenshot just shows the plain text representation of the FlowDocument
What I've tried
1
TextRange myrange = new TextRange(MainRtb.Selection.Start, MainRtb.Selection.End);
if (myrange.GetPropertyValue(Inline.TextDecorationsProperty).Equals(TextDecorations.Underline)) { }
2
TextRange myrange = new TextRange(MainRtb.Selection.Start, MainRtb.Selection.End);
var obj = myrange.GetPropertyValue(Inline.TextDecorationsProperty);
if (obj == DependencyProperty.UnsetValue) {
log.addLog("mix format");
}
if (obj is TextDecorationCollection) {
var objProper = obj as TextDecorationCollection;
if (objProper.Count > 0) {
log.addLog("all underlined");
} else {
log.addLog("none underlined");
}
}
3
foreach (Block block in MainRtb.Document.Blocks) {
Paragraph p = block as Paragraph;
if (p != null) {
foreach (Inline inline in p.Inlines) {
InlineUIContainer iuic = inline as InlineUIContainer;
if (iuic != null) {
Console.WriteLine("found underline");
}
}
}
}
Theory
This post https://social.msdn.microsoft.com/Forums/vstudio/en-US/3ac626cf-60aa-427f-80e9-794f3775a70e/how-to-tell-if-richtextbox-selection-is-underlined?forum=wpf suggests that
myrange.GetPropertyValue(Inline.TextDecorationsProperty)
doesn't work properly due to an issue inside the "GetPropertyValue()" method, but it's a very old post. I couldn't run Jim's solution exactly because he initialises an "IEnumerable" which now needs to be declared with a type of some kind - at least that's what VS2019 said.
Test Rtf File:
https://docs.google.com/document/d/1YQmGsPcH4hX2XsP7KBdFqTFg4XjrSv8I/edit?usp=sharing&ouid=111968029811979231347&rtpof=true&sd=true
Try the following method:
public static void GetDecorations(RichTextBox rtb)
{
TextDecorationCollection decors = rtb.Selection.GetPropertyValue(Inline.TextDecorationsProperty) as TextDecorationCollection;
if (decors == null || decors.Count == 0)
{
if (rtb.Selection.Start.Parent is Run run)
{
if (run.Parent is Span span)
{
decors = span.TextDecorations;
}
else if (run.Parent is Paragraph para)
{
decors = para.TextDecorations;
}
}
}
if (decors is TextDecorationCollection tdc)
{
// TODO: Processing decorations...
}
}
I suppose the problem you are discovered is related to the particular structure of the FlowDocument after loading your RTF document and it might be described as follow.
When the RTF document is loaded for the underlined text tBox. See TextPointer for more information on text position terminology like "insertion position" a Run inline is created for this text, but the Run.TextDecorations property doesn't contain the actual decorations for this text. Instead of that the decorations settings are stored in the parent Span object that contains this Run. In another words, these decorations property is inherited from parent to child.
Therefore, if no decorations property is set on the current Run object, then you should to check the TextDecorations property in the parent object.

Sitecore Rich Text editor customisation of link Insertions

When a user uses the "Insert Link" feature on the RTE to create stories, we get something like...<Item-Name-Of-Story
Instead of taking the Item name I would like to use another field called "Headline"
Does anyone know how to do this?...
Headline-Of-Story
Any help will be much appreciated. Thanks
First of all, you need need to look at this class with Reflector or DotPeek : Sitecore.Shell.Controls.RichTextEditor.InsertLink.InsertLinkForm and to modify it with your own class.
You need to modify just this method,I tested and works fine :
protected override void OnOK(object sender, EventArgs args)
{
Assert.ArgumentNotNull(sender, "sender");
Assert.ArgumentNotNull((object) args, "args");
string displayName;
string text;
if (this.Tabs.Active == 0 || this.Tabs.Active == 2)
{
Item selectionItem = this.InternalLinkTreeview.GetSelectionItem();
if (selectionItem == null)
{
SheerResponse.Alert("Select an item.", new string[0]);
return;
}
else
{
displayName = selectionItem["Headline"];
if (selectionItem.Paths.IsMediaItem)
text = CustomInsertLinkForm.GetMediaUrl(selectionItem);
else if (!selectionItem.Paths.IsContentItem)
{
SheerResponse.Alert("Select either a content item or a media item.", new string[0]);
return;
}
else
{
LinkUrlOptions options = new LinkUrlOptions();
text = LinkManager.GetDynamicUrl(selectionItem, options);
}
}
}
else
{
MediaItem mediaItem = (MediaItem) this.MediaTreeview.GetSelectionItem();
if (mediaItem == null)
{
SheerResponse.Alert("Select a media item.", new string[0]);
return;
}
else
{
displayName = mediaItem.DisplayName;
text = CustomInsertLinkForm.GetMediaUrl((Item) mediaItem);
}
}
if (this.Mode == "webedit")
{
SheerResponse.SetDialogValue(StringUtil.EscapeJavascriptString(text));
base.OnOK(sender, args);
}
else
SheerResponse.Eval("scClose(" + StringUtil.EscapeJavascriptString(text) + "," + StringUtil.EscapeJavascriptString(displayName) + ")");
}
After you modify this class you need to modify next file:
\sitecore\shell\Controls\Rich Text Editor\InsertLink\InsertLink.xml where you need to change codeBeside section
<CodeBeside Type="Sitecore.Shell.Controls.RichTextEditor.InsertLink.InsertLinkForm,Sitecore.Client"/>
with something like :
<CodeBeside Type="YourNameSpace.YourInsertLinkForm,YourAssembly"/>
The simplest way around this would be to type the desired link text, then select this before clicking 'insert link' - this way your hyperlink will have the text of whatever you entered, instead of defaulting to the item name.
If you want to modify how Sitecore renders links in RTE fields, you would need to modify the <renderField> pipeline - if you search for this in the web.config, you will see the different classes involved here. Using dotPeek you can decompile the Sitecore source to see how this works. Potentially you could then create your own renderField pipeline handler to change the link rendering behaviour and then reference this new class in your web.config.

Finding a graph part within a rich text control with OpenXML SDK

Hello fellow developers,
Being a newbie with the OpenXML SDK I cannot figure out how to retrieve a graph part that I've put in a rich text control (with a specific tag name).
For the moment I retrieve the graph part by using the mainDocumentPart.ChartParts collection. But a ChartPart object does not seem to know where it's located in the document: chartPart.GetParentParts() only contains the mainDocumentPart.
I have multiple graphs in my document, so how can I distinguish them?
I have put my graphs in rich text controls, so I thought I could access them like that, but I cannot figure out how to do this. Retrieving the rich text control works, but how to find the graph within it?
foreach (SdtProperties sdtProp in mainDocumentPart.Document.Body.Descendants<SdtProperties>())
{
Tag tag = sdtProp.GetFirstChild<Tag>();
if (tag != null && tag.Val != null)
{
if (tag.Val == "containerX")
{
SdtProperties sdtPropTestResults = sdtProp;
// How to retrieve the graph part??
// sdtPropTestResults.Descendants<ChartPart> does not seem to work
}
}
}
Thanks a lot for your help.
Found a solution myself. I don't use the parent container now. Instead I gave the chart space an "Alt Title". Now my code looks for a drawing having a docProperties with the given title.
Here it is:
// Find our graphs by looping all drawings in the document and comparing their "alt title" property
foreach (Drawing drawing in mainDocumentPart.Document.Body.Descendants<Drawing>())
{
DocProperties docProperties = drawing.Descendants<DocumentFormat.OpenXml.Drawing.Wordprocessing.DocProperties>().FirstOrDefault();
if (docProperties != null && docProperties.Title != null)
{
if (docProperties.Title.Value == AltTitleChartBlack || docProperties.Title.Value == AltTitleChartRed)
{
LineChartData lineChartData = null;
switch (docProperties.Title.Value)
{
case AltTitleChartBlack:
lineChartData = this.chartDataBlack;
break;
case AltTitleChartRed:
lineChartData = this.chartDataRed;
break;
}
ChartReference chartRef = drawing.Descendants<ChartReference>().FirstOrDefault();
if (chartRef != null && chartRef.Id != null)
{
ChartPart chartPart = (ChartPart)mainDocumentPart.GetPartById(chartRef.Id);
if (chartPart != null)
{
Chart chart = chartPart.ChartSpace.Elements<Chart>().FirstOrDefault();
if (chart != null)
{
LineChart lineChart = chart.Descendants<LineChart>().FirstOrDefault();
if (lineChart != null)
{
LineChartEx chartEx = new LineChartEx(chartPart, lineChartData);
chartEx.Refresh();
chartPart.ChartSpace.Save();
}
}
}
}
}
}
}

get the selected text of the editor window..visual studio extension

hi i'm making a extension for visual studio and the specific thing that i need is get the selected text of the editor windows for further processing. Someone know what interface or service has this?
Previously i need to locate the path of the open solution and for that i ask for a service that implements IVsSolution, so for this other problem I thing that there must be some service that provides me this information.
To clarify "just get the viewhost" in Stacker's answer, here is the full code for how you can get the current editor view, and from there the ITextSelection, from anywhere else in a Visual Studio 2010 VSPackage. In particular, I used this to get the current selection from a menu command callback.
IWpfTextViewHost GetCurrentViewHost()
{
// code to get access to the editor's currently selected text cribbed from
// http://msdn.microsoft.com/en-us/library/dd884850.aspx
IVsTextManager txtMgr = (IVsTextManager)GetService(typeof(SVsTextManager));
IVsTextView vTextView = null;
int mustHaveFocus = 1;
txtMgr.GetActiveView(mustHaveFocus, null, out vTextView);
IVsUserData userData = vTextView as IVsUserData;
if (userData == null)
{
return null;
}
else
{
IWpfTextViewHost viewHost;
object holder;
Guid guidViewHost = DefGuidList.guidIWpfTextViewHost;
userData.GetData(ref guidViewHost, out holder);
viewHost = (IWpfTextViewHost)holder;
return viewHost;
}
}
/// Given an IWpfTextViewHost representing the currently selected editor pane,
/// return the ITextDocument for that view. That's useful for learning things
/// like the filename of the document, its creation date, and so on.
ITextDocument GetTextDocumentForView( IWpfTextViewHost viewHost )
{
ITextDocument document;
viewHost.TextView.TextDataModel.DocumentBuffer.Properties.TryGetProperty(typeof(ITextDocument), out document);
return document;
}
/// Get the current editor selection
ITextSelection GetSelection( IWpfTextViewHost viewHost )
{
return viewHost.TextView.Selection;
}
Here's MSDN's docs for IWpfTextViewHost, ITextDocument, and ITextSelection.
Inside of the OnlayoutChanged, the following code would pop up a message with the code selected:
if (_view.Selection.IsEmpty) return;
else
{
string selectedText = _view.Selection.StreamSelectionSpan.GetText();
MessageBox.Show(selectedText);
}
Anywhere else, just get the viewhost and its _view of typeIWpfTextView

Categories

Resources