Binding Something in a Tooltip to a Property on the Parent Control

You can use data binding to bind the value of a simple Tooltip property to some other property of the control. But you might also want to use data binding when you create a Tooltip as a child element in XAML.

Suppose you want a Tooltip to include several labels and you want the Content of the second label to bind back to a property on the parent control.

You can do this by using the PlacementTarget of the Tooltip to find its parent and then set the DataContext of the Tooltip.

<TextBox Text="Now is the winter of our discontent etc"
    Width="100" Margin="10">
    <TextBox.ToolTip>
        <ToolTip DataContext="{Binding Path=PlacementTarget, RelativeSource={x:Static RelativeSource.Self}}">
            <StackPanel>
                <Label FontWeight="Bold" Content="Full Text"/>
                <Label Content="{Binding Text}"/>
                <Label Content="--Gloster, in Richard III (Act I, Scene I)"/>
            </StackPanel>
        </ToolTip>
    </TextBox.ToolTip>
</TextBox>

运行结果

In the provided document, the setup binding property `nowFirst` is indeed declared more than once, which can cause issues in the Vue application. Here are the specific instances where it is declared: 1. **Initial Declaration:** ```javascript const state = reactive({ nowFirst: 'projectCode', // other properties... }); ``` 2. **Redundant Declaration:** ```javascript const departChange = (val) => { if (val == 2) { nowFirst.value = 'orgCode_dictText'; // other logic... } else { nowFirst.value = 'projectCode'; // other logic... } columnsKey.value += 1; }; ``` ### Solution To resolve this issue, you should ensure that `nowFirst` is only declared once in the `state` object. The `departChange` function can then modify the `nowFirst` property as needed without redeclaring it. Here is the corrected version of the relevant parts of the code: 1. **State Initialization:** ```javascript const state = reactive({ nowFirst: 'projectCode', columnsKey: 0, projectNameList: [], projectName_Code: '', projectBudgetMarginWarning: 0, expandedRowKeys: [], workorderProjectList: [], description: '营业报表管理页面', fastTime: ['本月', '上月', '近半年'], noCreate: true, hasUpdateTime: true, configOrderSubTypeList: [], configOrderSubTypeTemp: undefined, allDepartList: [], hallCodeDataList: [], spinning: false, checkFlag: true, updateTime: '', url: { list: "/web/materialVoucherDetails/getProjectMaterialStatistic", exportXlsxUrl: "/web/materialVoucherDetails/exportProjectMaterialStatisticExcel", exportPdfUrl: "/web/bizBusinessRecord/exportpdf", exportDetailUrl: "/web/bizBusinessRecord/exportDetailExcel" }, keyList: ['saleNum', 'saleName', 'terminalTypeName', 'userTypeName', 'configOrderMainTypeName', 'configOrderSubTypeName'], ipagination: { current: 1, pageSize: 20, pageSizeOptions: ['20', '50', '80'], showTotal: (total, range) => `${range[0]}-${range[1]} 共 ${total} 条`, showQuickJumper: true, showSizeChanger: true, total: 0 }, originColums: [], columns: [ // column definitions... ], queryParam: { type: '', projectCode: '', projectName: '', projectName_Code: "", subProjectName: '', departId: '', material: '', producerId: '', specification: '', materialInventoryResult: '', projectDateBegin: '', projectDateEnd: '' }, dataSource: [], loading: false, toggleSearchStatus: false }); ``` 2. **Function to Change `nowFirst`:** ```javascript const departChange = (val) => { if (val == 2) { state.nowFirst = 'orgCode_dictText'; let objectArray = deepClone(state.originColums); let movedElement = objectArray.splice(3, 1)[0]; objectArray.unshift(movedElement); state.columns = objectArray; } else { state.nowFirst = 'projectCode'; state.columns = deepClone(state.originColums); } state.columnsKey += 1; }; ``` By making these changes, you ensure that `nowFirst` is only declared once and can be modified as needed within the `departChange` function. This will prevent any potential conflicts or errors in your Vue application.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sdhongjun

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值